[GRADLE-1411] Failed to create MANIFEST when building a web app as OSGi bundle Created: 02/Mar/11  Updated: 10/Feb/17  Resolved: 10/Feb/17

Status: Resolved
Project: Gradle
Affects Version/s: 0.9.2, 1.0-milestone-1
Fix Version/s: None

Type: Bug
Reporter: Wolfgang Schell Assignee: Unassigned
Resolution: Won't Fix Votes: 4

Attachments: Zip Archive jetztgradnet-gradle-web-bundle-4fce0ff.zip    

 Description   

Hi all,

I'm building a web app as OSGi bundle (web bundle), so I use both the OSGi and war plugins. Both Gradle 0.9.2 and 1.0-milestone-1 fail to build the war's MANIFEST.MF when called like this:

war {
manifest = osgiManifest

{ instruction 'Web-ContextPath', '/' instruction 'Import-Package', '*' }
}


* What went wrong:
Could not copy MANIFEST.MF to '/Users/wolfgang/dev/workspaces/grails/gradle-web-bundle/build/tmp/war/MANIFEST.MF'.

* Exception is:
org.gradle.api.GradleException: Could not copy MANIFEST.MF to '/Users/wolfgang/dev/workspaces/grails/gradle-web-bundle/build/tmp/war/MANIFEST.MF'.
at org.gradle.api.internal.file.AbstractFileTreeElement.copyTo(AbstractFileTreeElement.java:65)
at org.gradle.api.internal.file.MapFileTree$FileVisitDetailsImpl.getFile(MapFileTree.java:125)
...[snip]...
Caused by: java.lang.NullPointerException
at aQute.lib.osgi.Jar.getName(Jar.java:65)
at aQute.lib.osgi.Jar.(Jar.java:55)
at aQute.lib.osgi.Analyzer.setJar(Analyzer.java:699)
at org.gradle.api.internal.plugins.osgi.DefaultOsgiManifest.setAnalyzerProperties(DefaultOsgiManifest.java:90)
at org.gradle.api.internal.plugins.osgi.DefaultOsgiManifest.getEffectiveManifest(DefaultOsgiManifest.java:64)
at org.gradle.api.java.archives.internal.DefaultManifest.writeTo(DefaultManifest.java:152)
at org.gradle.api.java.archives.internal.DefaultManifest.writeTo(DefaultManifest.java:36)
at org.gradle.api.java.archives.Manifest$writeTo.call(Unknown Source)
at org.gradle.api.tasks.bundling.Jar$_closure1_closure3.doCall(Jar.groovy:47)
at org.gradle.api.internal.file.MapFileTree$FileVisitDetailsImpl.copyTo(MapFileTree.java:143)
at org.gradle.api.internal.file.AbstractFileTreeElement.copyFile(AbstractFileTreeElement.java:72)
at org.gradle.api.internal.file.AbstractFileTreeElement.copyTo(AbstractFileTreeElement.java:60)
... 40 more


BUILD FAILED

Total time: 1.613 secs

When looking into Bnd's and Gradle's code it seems, that DefaultOsgiManifest's classesDir is not set, so Bnd fails when to analyze the class files. (see DefaultOsgiManifest#setAnalyzerProperties() at https://github.com/gradle/gradle/blob/master/subprojects/osgi/src/main/groovy/org/gradle/api/internal/plugins/osgi/DefaultOsgiManifest.java#L90)

If I don't use the OSGi plugin at this place, it works:

war {
manifest { attributes ('Bundle-SymbolicName': baseName, 'Bundle-Version': version, 'Web-ContextPath': '/') }
}

But obviously I have to set all bundle headers myself.

Using the same code for a bundle (jar file) works without problems:

jar {
manifest { instruction 'Web-ContextPath', '/' instruction 'Import-Package', '*' }

}

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.

I posted an example project at https://github.com/jetztgradnet/gradle-web-bundle. It's also attached to this issue.

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.



 Comments   
Comment by Wolfgang Schell [ 30/Mar/11 ]

It works if I manually specify classesDir and classpath as in this example:

war {
        manifest = osgiManifest {
                classesDir = sourceSets.main.classesDir
                classpath = configurations.runtime
                instruction 'Web-ContextPath', '/'
                instruction 'Import-Package', '*'
        }
}
Comment by Brett Meyer [ 24/Jan/13 ]

This is still an issue in 1.1. The following is a working example:

jar {
    manifest = osgiManifest {
        // GRADLE-1411
        classesDir = sourceSets.main.output.classesDir
        classpath = configurations.runtime
        ...
    }
}

Without both classesDir and classpath available, the same failure and stacktrace results.

Comment by Benjamin Muschko [ 15/Nov/16 ]

As announced on the Gradle blog we are planning to completely migrate issues from JIRA to GitHub.

We intend to prioritize issues that are actionable and impactful while working more closely with the community. Many of our JIRA issues are inactionable or irrelevant. We would like to request your help to ensure we can appropriately prioritize JIRA issues you’ve contributed to.

Please confirm that you still advocate for your JIRA issue before December 10th, 2016 by:

  • Checking that your issues contain requisite context, impact, behaviors, and examples as described in our published guidelines.
  • Leave a comment on the JIRA issue or open a new GitHub issue confirming that the above is complete.

We look forward to collaborating with you more closely on GitHub. Thank you for your contribution to Gradle!

Comment by Benjamin Muschko [ 10/Feb/17 ]

Thanks again for reporting this issue. We haven't heard back from you after our inquiry from November 15th. We are closing this issue now. Please create an issue on GitHub if you still feel passionate about getting it resolved.

Generated at Wed Jun 30 11:54:51 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.