Building and deploying SNAPSHOT and RELEASE Versions for maven with BND

BND is a nice build tool, but in some cases it makes actually trivial things, seem impossible or at least not really obvious. Doing RELEASE and SNAPSHOT Builds is one of these things. Thus, here is a quick guide on how this can be done.

By default OSGi uses Semantic Versions like 2.6.122.20191126120000. The last part is called the qualifier and is usually a timestamp. Maven versions look close to OSGi versions. SNAPSHOT builds are marked as 1.0.0-SNAPSHOT and Maven will replace the SNAPSHOT with a timestamp qualifier for you. BND offers a similar Mechanism, given that each Project will get a Version that ends with .SNAPSHOT.

The Setup

For your build.bnd

# We need an indicator, if we want to do a release or snapshot  build. This macro looks for the Environment variable release.marker.
# If set the release.bnd will be included. If not the snapshot.bnd will be included.

-include: ${if;${def;release.marker};\               
${.}/releng/release.bnd;\               
${.}/releng/snapshot.bnd\           
}

# We need a Maven repository to deploy to. In this example it is a Nexus. NOTE: From time to time there is a Problem, when bnd needs to follow  redirects from http to https on deployment. 

# Thus always use https Urls, if you have HTTPS.
-plugin.nexus.release: \     
aQute.bnd.repository.maven.provider.MavenBndRepository;\         
snapshotUrl=https://devel.data-in-motion.biz/nexus/repository/maven-
snapshots/;\         
releaseUrl=https://devel.data-in-motion.biz/nexus/repository/maven-
releases/;\         
index=${.}/dim_nexus.maven;\         
name='DIM_Nexus'

# The group ID to use
-groupid: de.dim
# instructs bnd to create and package a pom.xml
-maven-release: pom
# define what repository should be used for the release. This can be coma separated list, if you have more then one 
-releaserepo: DIM_Nexus

/cnf/releng/release.bnd

#We have to substitude the -SNAPSHOT with an empty String for releases or 
anything else                
-snapshot: 

/cnf/releng/snapshot.bnd

# instructs bnd to create the SNAPSHOT Versions for the pom.xml-pom: version=${versionmask;===s;${@version}}

Well, that’s about it. If you want to build and deploy a snapshot, you have to use the release task:

gradlew release

if you want to build and deploy a release use the release task with our release marker property:

gradlew release -Drelease.marker=true

If you need to provide credentials for your maven repository, have a look at the bnd documentation for the issue here<

by Ilenia Salvadori, Mark Hoffmann, Jürgen Albert