Skip to content

rife2/bld-generated-version

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.