VersionInfoBundle
is a simple Dropwizard bundle which exposes a
version string as a Jersey resource under /version
.
-
Create a version.properties file that contains a
productVersion
key in the <project_dir>/src/main/resources/. It should look something like this:productVersion: <version>
If the properties file cannot be read (for example, because of an incorrect path or an IO error), the bundle will throw a
RuntimeException
on construction. If the properties file can be read, but theproductVersion
key cannot be found, then the version will be "unknown". -
Add the
com.palantir.versioninfo:dropwizard-version-info:<VERSION>
dependency to your project's build.gradle file. The most recent version number can be found in the [Relase Notes] (https://github.com/palantir/dropwizard-version-info/releases). The dependencies section should look something like this:dependencies { // ... unrelated dependencies omitted ... compile "com.palantir.versioninfo:dropwizard-version-info:<VERSION>" }
-
Add the bundle in your Dropwizard application's
initialize
method (or create one if it doesn't already exist). It should look something like this:@Override public void initialize(Bootstrap<MyConfiguration> bootstrap) { bootstrap.addBundle(new VersionInfoBundle()); }
-
Run your server, then access
<API_ROOT>/version
. The<API_ROOT>
is defined by therootPath
andapplicationContextPath
in your Dropwizard server configuration. -
If your application uses Feign to build clients, make sure your service interface extends VersionInfoService interface. The dependencies section for your
-api
project should look like this:dependencies { // ... unrelated dependencies omitted ... compile "com.palantir.versioninfo:dropwizard-version-info-api:<VERSION>" }
Your service interface should look like this:
public interface ExampleService extends VersionInfoService { @GET @Path("hello") @Produces(MediaType.TEXT_PLAIN) String hello(); }
To load the version.properties file from somewhere else in the classpath, pass the path to it as an argument to the bundle's constructor:
@Override
public void initialize(Bootstrap<MyConfiguration> bootstrap) {
bootstrap.addBundle(new VersionInfoBundle("/properties/info.properties"));
}
To generate the product version from Git, use the Git-Version Gradle Plugin.
You can use the write-version.gradle
script to write the version from git into the version.properties
file:
-
In your
build.gradle
, include thewrite-version.gradle
dependency:apply from: "${rootDir}/write-version.gradle"
-
Set your compile task to depend on the generation of the version file:
compileJava.dependsOn writeVersion
-
Set your
.gitignore
to ignore changes to theversion.properties
file:*version.properties