public abstract class BuildInfo extends Object
Generally, you would create this by loading a properties file created by Maven resource filtering. If you create the following file in src/main/resources/com/cerner/mypackage/build-info.properties
Required properties:
git.commit.id=${git.commit.id} project.artifactId=${project.artifactId} project.groupId=${project.groupId} project.version=${project.version}
Optional properties:
project.build.date=${mvn.build.timestamp}
If using project.build.date property in the build-info.properties file create the timestamp property in the pom.xml.
<properties>
<mvn.build.timestamp>${maven.build.timestamp}</mvn.build.timestamp>
</properties>
Maven does not let you pass the maven.build.timestamp property that's why this work around is needed. If curious about the reason Ref: https://issues.apache.org/jira/browse/MRESOURCES-99.
And ensure resource filtering and the git-commit-id-plugin are enabled in your pom:
<build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> </build> <plugins> <plugin> <groupId>pl.project13.maven</groupId> <artifactId>git-commit-id-plugin</artifactId> </plugin> </plugins>
You could then create an instance by using the following code within src/main/java/com/cerner/mypackage/SomeClass.java
BuildInfo.load(getClass().getResourceAsStream("build-info.properties"));
Modifier and Type | Class and Description |
---|---|
static class |
BuildInfo.Builder |
Constructor and Description |
---|
BuildInfo() |
Modifier and Type | Method and Description |
---|---|
static BuildInfo.Builder |
builder() |
static BuildInfo.Builder |
builder(BuildInfo buildInfo) |
static BuildInfo |
create(Properties properties)
Create an instance using the given properties.
|
abstract String |
getArtifactId()
Returns the artifact Id.
|
abstract Optional<String> |
getBuildDateTime()
Returns the the build date/time.
|
abstract String |
getGroupId()
Returns the group Id for the artifact.
|
abstract Properties |
getRawProperties()
Returns all build properties that were passed in when this object was created.
|
abstract String |
getScmRevision()
Returns the SCM commit revision at which the artifact was built.
|
abstract String |
getVersion()
Returns the version of the artifact.
|
static BuildInfo |
load(InputStream propertiesStream)
Creates an instance using properties from the given stream (which must be in property file
format).
|
abstract BuildInfo.Builder |
toBuilder()
Returns a builder with same property values as this; allowing modification of some values.
|
public static BuildInfo.Builder builder()
public static BuildInfo.Builder builder(BuildInfo buildInfo)
public static BuildInfo create(Properties properties)
Currently, at least the following properties are required:
Optional properties:
public static BuildInfo load(InputStream propertiesStream)
See create(Properties)
for a list of required properties.
For convenience, this method throws a runtime exception if an IOException occurs. If you
plan to do anything other than crash in the event of an error, you should use
create(Properties)
instead.
public abstract String getArtifactId()
public abstract String getGroupId()
public abstract Properties getRawProperties()
public abstract String getScmRevision()
public abstract String getVersion()
public abstract Optional<String> getBuildDateTime()
public abstract BuildInfo.Builder toBuilder()
Copyright © 2019 Cerner Innovation, Inc.. All rights reserved.