IBM / cics-bundle-maven

The plugin to build and deploy CICS bundles in a Maven build.
https://ibm.github.io/cics-bundle-maven/plugin-info.html
Eclipse Public License 2.0
18 stars 25 forks source link

Building OSGi bundles with maven-bundle-plugin results in "Error reading Bundle-SymbolicName from OSGi manifest file" #197

Open holgerknoche opened 2 years ago

holgerknoche commented 2 years ago

Consider the following multi-module Maven project. One module is an OSGi bundle built with the maven-bundle-plugin. The other module is a CICS bundle that includes the OSGi bundle. Building the entire project with "mvn compile" fails with the error message "Error reading Bundle-SymbolicName from OSGi manifest file". Building it with "mvn package" or "mvn install" works fine. The maven-bundle-plugin creates the bundle manifest after compilation (in the process-classes phase), as it inspects the class files to determine which packages to import and export. Maybe the check for the symbolic name could be moved so that it is only executed when an actual packaging occurs.

jsventura commented 1 year ago

Hi @holgerknoche, how do you solve this problem ?

holgerknoche commented 1 year ago

Hi @jsventura, we actually just avoid building the projects with "mvn compile". Since the goals we really need are "package" and "install" and those work fine, this issue is not really a problem for us. Maybe it would be enough to move the goal from the "compile" phase to the "package" phase, but I have not tried this yet.

stewartfrancis commented 1 year ago

I've been able to reproduce this, and I'm pretty sure it's to do with our default lifecycle bindings when you're using the cics-bundle packaging type. I'll work on a fix for this to build the bundle as late as possible in reactor builds, probably changing the binding for all plugins to the package phase but that will require a new plugin major version. Also not been able to quite get that working yet.

In the mean time I was able to work around this by changing the phase bound to the bundle plugin's build goal:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>stewf</groupId>
    <artifactId>parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>cics</artifactId>

  <packaging>cics-bundle</packaging>

  <dependencies>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>osgi</artifactId>
      <version>${project.version}</version>
      <type>jar</type>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>com.ibm.cics</groupId>
        <artifactId>cics-bundle-maven-plugin</artifactId>
        <version>1.0.3</version>
        <extensions>true</extensions>
        <configuration>
          <jvmserver>asdf</jvmserver>
        </configuration>
        <executions>
          <execution>
            <id>default-build</id> <!-- You must set this execution ID for this to work -->
            <phase>package</phase> <!-- rebind the default execution to the package phase -->
            <goals>
              <goal>build</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>

Note that the latest phase you'll be able to run this in at the moment is package without also changing the lifecycle phase of the cics bundle package plugin too. I can explain further if that's useful, but hopefully that's not an issue for you.

I'll put together something to address the default lifecycle phase in a future release of the plugin, hopefully you can make do with the workaround for now.