Sorry, your blog cannot share posts by email. (the Git commit hash for example). An advantage of using Gradle is that attribute values may be computed on the spot, as you have access to a full programming language (either Groovy or Kotlin), useful when you may need to trim, modify, and/or format certain values. One option we have to mitigate this problem is to provide additional metadata as part of the artifact’s archive. Please check the checkbox to ensure that you comply with the EU Laws. $ jar tvf build/libs/gs-gradle-0.1.0.jar 0 Fri May 30 16:02:32 CDT 2014 META-INF/ 25 Fri May 30 16:02:32 CDT 2014 META-INF/MANIFEST.MF 0 Fri May 30 16:02:32 CDT 2014 hello/ 369 Fri May 30 16:02:32 CDT 2014 hello/Greeter.class 988 Fri May 30 16:02:32 CDT 2014 hello/HelloWorld.class Gradle let’s you customize archive manifest from the get go, you just have to add entries you desired to the manifest’s attributes. Both Gradle 0.9.2 and 1.0-milestone-1 fail to build the war's MANIFEST.MF when called like this: So basically it seems that a call to DefaultOsgiManifest#setClassesDir() is omitted, maybe because a web app's classes are located at a different location as a normal jar. jar { LinkedHashMap attributes = new LinkedHashMap() attributes.put('Build-Date', new Date().format("yyyy-MM-dd")) attributes.put('Build-Time', new Date().format("HH:mm:ssZ")) attributes.put('Code-Revision', '1.0') attributes.put( 'Class-Path', configurations.compile.collect { it.getName() }.join(' ')) manifest.mainAttributes(attributes) } Gradle let’s you customize archive manifest from the get go, you just have to add entries you desired to the manifest’s attributes. The OSGI plugin updates the MANIFEST.MF with a new Bnd-LastModified even if there is no other change, resulting in the jar task always executing. In any case, both build tools provide you the means to add essential artifact metadata to the archive’s manifest. Take a second to support aalmiray on Patreon! Post was not sent - check your email addresses! Liked it? We could write down said metadata to a properties file and add it to the package archive, or we could reuse an existing facility: the archive’s manifest. Alrighty the solution was to update gradle on build.gradle of my project, not module // Top-level build file where you can add configuration options common to all sub-projects/modules. I posted an example project at https://github.com/jetztgradnet/gradle-web-bundle. On closer inspection (after unpacking, debugging, even decompiling!) Learn how your comment data is processed. Click to share on Twitter (Opens in new window), Click to share on LinkedIn (Opens in new window), Click to share on Reddit (Opens in new window), Click to email this to a friend (Opens in new window). It's also attached to this issue. I'm building a web app as OSGi bundle (web bundle), so I use both the OSGi and war plugins. Just like in Gradle, the build file has access to all System properties we need (more information about project properties can be found at this link). Manifest-Version is set to 1.0; Specification-Title and Implementation-Title are set to the Gradle rootProject.name; Specification-Version and Implementation-Version are set based on Git commit status (see git describe) IFF no version can be determined via a git describe, and a Gradle rootProject.version can be, this value will be used instead Perhaps you may be thinking in using the antrun plugin with a short embedded script to be able to get around this problem, well, if you need to bring a second build tool in order to fix the shortcomings of the first, isn’t the problem somewhere else? Values must exist as standard project properties, System properties, or custom project properties, such as the ones exposed by the git-commit-id plugin or any other plugin. Your email address will not be published. Try Jira - bug tracking software for your team. The only drawback I see with using Maven in this way is that it’s not possible to format values or create new ones on the spot. Your email address will not be published. Personally I’d like to find out the following information when inspecting the metadata for a particular artifact: Let’s start with Gradle as it’s the one that requires less setup. There’s a catch though, Gradle does not know a thing about SCM properties, you’ll have to add a plugin that exposes this information, such as the net.nemerosa.versioning plugin. To raise new issues or bugs against Gradle, please use, https://github.com/gradle/gradle/blob/master/subprojects/osgi/src/main/groovy/org/gradle/api/internal/plugins/osgi/DefaultOsgiManifest.java#L90, https://github.com/jetztgradnet/gradle-web-bundle, jetztgradnet-gradle-web-bundle-4fce0ff.zip. In this case we must also configure an external plugin in order to grab hold of SCM properties, we’ll use the maven-git-commit-id-plugin from Konrad (@ktosopl); we’ll also need to update the configuration of the core maven-jar-plugin as explained here. The following snippet shows the minimum configuration to setup the metadata that answers my previous questions: Packaging the artifact and inspecting the generated manifest (found already unpacked at build/tmp/jar/MANIFEST.MF) we may see something like this. What’s the SCM reference? As you can see we get the expected result. Powered by a free Atlassian Jira open source license for Gradle Inc. How many times have you found yourself in a situation where you can’t tell if the artifacts used by the application are the correct ones or not? Which JDK version was used to compile the classes? Both Gradle 0.9.2 and 1.0-milestone-1 fail to build the war's MANIFEST.MF when called like this: Which operating system was used to built it. Required fields are marked *. Gradle Kotlin DSL: set main class attribute for jar - build.gradle.kts Next is Maven. For my simple test case I can live with the workaround, as I don't need Bnd to calculate imports or exports, but for real web bundles, this is a problems that needs to be resolved. It looks quite similar to the one generated by Gradle with just the timestamp and the creator having different values. Hi all, I'm building a web app as OSGi bundle (web bundle), so I use both the OSGi and war plugins. Notify me of follow-up comments by email. When packaging the project we get a manifest that may look like this. How many times have you looked at a bug report stating that the problem is caused by version X of a particular artifact but you are certain the bug was fixed in said release? This site uses Akismet to reduce spam. There’s a catch though, Gradle does not know a thing about SCM properties, you’ll have to add a plugin that exposes this information, such as … you find that the artifact in production is not the right one even though the version appears to be the correct one. This triggers downstream tasks …