bld Extension to Generate Project Version Data https://github.com/rife2/bld-generated-version
Find a file
2023-11-27 11:52:48 -08:00
.github/workflows Updated copyright 2023-08-28 14:45:31 -07:00
.idea Verison 0.9.3 2023-11-13 16:40:07 -08:00
.vscode Upgraded to RIFE2 1.7.0 2023-05-12 15:21:20 -07:00
config Initial commit 2023-04-27 22:36:49 -07:00
examples Cleaned up Javadocs 2023-11-27 11:52:48 -08:00
lib/bld Version 0.9.2 2023-10-22 14:52:50 -07:00
src Cleaned up Javadocs 2023-11-27 11:52:48 -08:00
.gitignore Updated gitignore 2023-04-28 10:29:07 -07:00
bld Initial commit 2023-04-27 22:36:49 -07:00
bld.bat Initial commit 2023-04-27 22:36:49 -07:00
LICENSE.txt Initial commit 2023-04-27 22:36:49 -07:00
README.md Cleaned up Javadocs 2023-11-27 11:52:48 -08:00

bld Extension to Generate a Project Version Data Class

License Java bld Release Snapshot GitHub CI

To install, please refer to the extensions documentation.

To automatically create a generated version class using the default template in your project on compile, add the following to your build file:

@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 MyAppVersion class")
public void genver() throws Exception {
    new GeneratedVersionOperation()
        .fromProject(this)
        .projectName("My App")
        .packageName("com.example.myapp")
        .className("MyAppVersion")
        .classTemplate(new File(workDirectory, "myversion.txt"))
        .execute();
}
// myversion.txt

package {{v packageName/}};

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;

public final class {{v className/}} {
    public static final String PROJECT = "{{v project/}}";
    public static final LocalDateTime BUILD_DATE = Instant.ofEpochMilli({{v epoch/}}L)
            .atZone(ZoneId.systemDefault()).toLocalDateTime();
    public static final String VERSION = "{{v version/}}";
    
    private {{v className/}}() {
        // no-op
    }
}

Please check the GeneratedVersionOperation documentation for all available configuration options.