Java, Maven, and Gradle
The integrations launch nbgv directly and consume the versioned
adapter JSON contract. Install the native Rust or .NET nbgv CLI and
make it available on PATH, set NBGV_EXECUTABLE, or use the adapter-specific
executable setting.
Packages
| Integration | Coordinate |
|---|---|
| Shared adapter | com.microsoft.nerdbank-gitversioning:nbgv-adapter:0.1.0 |
| Maven core extension | com.microsoft.nerdbank-gitversioning:nbgv-maven-extension:0.1.0 |
| Gradle implementation | com.microsoft.nerdbank-gitversioning:nbgv-gradle-plugin:0.1.0 |
| Gradle plugin ID | com.microsoft.nerdbank-gitversioning |
The adapter and Maven extension are available from Maven Central. The Gradle plugin is available from the Gradle Plugin Portal. The published bytecode targets Java 8. See the Java README for contributor build instructions.
Gradle plugin
Apply the plugin in your Gradle build:
plugins {
id 'java-library'
id 'maven-publish'
id 'com.microsoft.nerdbank-gitversioning' version '0.1.0'
}
The plugin sets project.version, Maven/Ivy publication versions, and JAR
manifest attributes. Configure an explicit executable with:
nbgv {
executable = '/tools/nbgv'
}
Maven core extension
Add the extension to .mvn/extensions.xml:
<extensions>
<extension>
<groupId>com.microsoft.nerdbank-gitversioning</groupId>
<artifactId>nbgv-maven-extension</artifactId>
<version>0.1.0</version>
</extension>
</extensions>
The extension stamps project models before Maven indexes the reactor.
It discovers the active reactor's modules first, using Maven's profile activation and property interpolation, so literal dependency versions are updated before effective models are constructed regardless of module order.
Maven 3 publishing should use CI-friendly ${revision} plus flatten-maven-plugin; detailed configuration and Maven 4 notes are in the
Java README.
Migrate an existing build
- Remove other plugins or scripts that assign
project.versionfrom Git. - Keep a harmless Maven
${revision}fallback so the reactor can be read before the extension replaces it. - Apply the Gradle plugin only once to each versioned project and remove custom manifest stamping for attributes it owns.
- Remove automatic
-SNAPSHOTsuffixing if immutable Nerdbank.GitVersioning SemVer is required. - Verify artifact versions and manifest metadata in a test publication before releasing your project.