bld Extension to Generate Project Version Data https://github.com/rife2/bld-generated-version
Find a file
2025-03-28 12:07:07 -07:00
.github/workflows Add OS matrix with Ubuntu, Windows and macOS 2025-03-25 00:19:50 -07:00
.idea Cleanup copyright template 2025-03-18 12:39:20 -07:00
.vscode Bump bld to version 2.2.1 2025-02-25 10:28:08 -08:00
config Updated dependencies 2024-10-27 16:09:33 -07:00
examples Version 1.0.1 2025-03-28 12:07:07 -07:00
lib/bld Bump PMD extension from 1.2.1 to 1.2.2 2025-03-28 12:04:22 -07:00
src Version 1.0.1 2025-03-28 12:07:07 -07: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 Add generic installation instructions 2025-03-18 12:40:49 -07:00

bld Extension to Generate a Project Version Data Class

License Java bld Release Snapshot GitHub CI

To install the latest version, add the following to the lib/bld/bld-wrapper.properties file:

bld.extension-generated-version=com.uwyn.rife2:bld-generated-version

For more information, please refer to the extensions documentation.

Generate Version Data Class

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.