bld Extension to Generate Project Version Data https://github.com/rife2/bld-generated-version
Find a file
2025-02-25 10:24:57 -08:00
.github/workflows Update pages actions to latest versions 2025-02-25 10:24:57 -08:00
.idea Version 1.0.0 2025-01-14 11:07:20 -08:00
.vscode Bumped bld to version 2.2.0 2025-01-14 00:39:45 -08:00
config Updated dependencies 2024-10-27 16:09:33 -07:00
examples Version 1.0.0 2025-01-14 11:07:20 -08:00
lib/bld Bumped bld to version 2.2.0 2025-01-14 00:39:45 -08:00
src Version 1.0.0 2025-01-14 11:07:20 -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 Bumped bld to version 2.2.0 2025-01-14 00:39:45 -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("my_app_version.txt")
        .execute();
}
// my_app_version.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.