Uploaded image for project: 'Gradle'
  1. Gradle
  2. GRADLE-1411

Failed to create MANIFEST when building a web app as OSGi bundle

    Details

    • Type: Bug
    • Status: Resolved
    • Resolution: Won't Fix
    • Affects Version/s: 0.9.2, 1.0-milestone-1
    • Fix Version/s: None

      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.

        Activity

        Hide
        jetztgradnet Wolfgang Schell added a comment -

        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', '*'
                }
        }
        
        Show
        jetztgradnet Wolfgang Schell added a comment - 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', '*' } }
        Hide
        brmeyer Brett Meyer added a comment -

        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.

        Show
        brmeyer Brett Meyer added a comment - 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.
        Hide
        bmuschko Benjamin Muschko added a comment -

        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!

        Show
        bmuschko Benjamin Muschko added a comment - 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!
        Hide
        bmuschko Benjamin Muschko added a comment -

        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.

        Show
        bmuschko Benjamin Muschko added a comment - 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.

          People

          • Assignee:
            Unassigned
            Reporter:
            jetztgradnet Wolfgang Schell
          • Votes:
            4 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development