Extracting Bundle Version from MANIFEST.MF for gradle jar task

Hi,

I am using gradle to build my eclipse plugins. I would like to synchronize the bundle version used in the manifest file with the Gradle Jar Version property. Is there an easy way to do this?

Cheers, Aguero

Setting the ‘version’ property on your project should propagate to your jar and manifest.

jar {

version = ‘1.0.1.qualifier’ }

But the jar name came out as com.foo.bar-1.0.1.qualifier.jar

The literal value of ‘version’ is going to be appended to the archive name. Perhaps what you really mean is this?

jar {

classifier = ‘qualifier’

version = ‘1.0.1’

}

Yes, but gradle does not automatically replace the word “qualifier” with a generated qualifier, unlike the PDE build.

You are correct. Grade nor the OSGi plugin provides this capability. Implementing this in your build script would be pretty trivial though.

Yes. I can generate a timestamp in gradle easily. But the problem is I do not generate a new manifest in gradle, but rather i merged from the Manifest file in my project, using

https://www.gradle.org/docs/current/groovydoc/org/gradle/api/java/archives/Manifest.html#from(java.lang.Object)

The catch is the manifest attributes are a HashMap and the Manifest API do not have a way to change the value of an attribute.

Eg: If my MANIFEST.MF file has a ‘Bundle-Version’ entry already, I cannot overwrite the value.

jar {

manifest {

def mf = projectDir.getAbsolutePath() + “/META-INF/MANIFEST.MF”

from file(mf)

attributes(‘Bundle-Version’: ‘1.newversion.doesnotwork’)

} }

Ok. Think I found a work-around. The updated bundle version will be 1.0.2

ext.sharedManifest = manifest {

attributes(‘Bundle-Version’: ‘1.0.2’) }

jar {

manifest {

def mf = projectDir.getAbsolutePath() + “/META-INF/MANIFEST.MF”

from file(mf)

from sharedManifest

} }

You can modify the value during the merge.

jar {

manifest {

from(‘META-INF/MANIFEST.MF’) {

eachEntry { details ->

if (details.key == ‘Bundle-Version’) {

details.value = ‘1.0.2’

}

}

}

}

}

To modify the qualifer for features (feature.xml) may be tougher since gradle has no utilities to manipulate the feature.xml files?

http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Ffeature_manifest.html

Not feature manifests specifically. You could however use Groovy’s built-in XML support.