bld-generated-version/README.md

2.7 KiB
Executable file

Bld Extension to Generate a Project Version Data Class

License (3-Clause BSD) Java Release Snapshot GitHub CI

To automatically create a generated version class using the default template in your project on compile:

@Override
public void compile() throws Exception {
    genver();
    super.compile();
}

@BuildCommand(summary = "Generates version class")
public void genver() throws Exception {
    new GeneratedVersionOperation()
        .fromProject(this)
        .execute();
}
./bld compile

Version Class Template

This is the default template:

package {{v packageName/}};

import java.util.Date;

public final class {{v className/}} {
    public static final String PROJECT = "{{v project/}}";
    public static final Date BUILD_DATE = new Date({{v epoch/}}L);
    public static final int MAJOR = {{v major/}};
    public static final int MINOR = {{v minor/}};
    public static final int REVISION = {{v revision/}};
    public static final String QUALIFIER = "{{v qualifier/}}";
    public static final String VERSION = "{{v version/}}";
    
    private {{v className/}}() {
        throw new UnsupportedOperationException("Illegal constructor call.");
    }
}

Custom Template

You can specified your own template using some or all of the template value tags, as follows:

@BuildCommand(summary = "Generates version class")
public void genver() throws Exception {
    new GeneratedVersionOperation()
        .fromProject(this)
        .classTemplate(new File(workDirectory, "myversion.txt"))
        .execute();
}

Please check the GeneratedVersionOperation documentation for all available configuration options.