Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy OSGi bundle to Maven repo with deploy:deploy-file?

I have an OSGi bundle that was built using Maven by another team. The POM file declares its packaging as "bundle" and uses the Apache Felix plugin.

I need to deploy this artifact to a local Maven repository (Nexus) so that it can be used by our internal projects.

I have used the deploy:deploy-file target to deploy the bundle to the repository, just as you would with a standard JAR file and this works without error. I extracted the embedded POM from the bundle and passed that on the command line, so the command line was:

mvn deploy:deploy-file -Dfile=3rdpartybundle.jar -DpomFile=pom.xml -DrepositoryId=internal -Durl=http://internalserver/nexus

The issue is that when I deploy it like this, the packaging is set to bundle and as a result the name of the artifact in the repository ends up with a .bundle extension, instead of a .jar extension.

Now, we cannot figure out how to declare it as a dependency. If we declare it like this:

        <dependency>
            <groupId>...</groupId>
            <artifactId>...</artifactId>
            <version>...</version>
            <type>bundle</type>
        </dependency>

We get an error stating that the dependency cannot be resolved. The interesting thing is that the GAV coordinates in the error message actually has "jar" as the value for the type of the dependency even though we set it as "bundle".

If we change the dependency to:

        <dependency>
            <groupId>...</groupId>
            <artifactId>...</artifactId>
            <version>...</version>
            <type>jar</type>
        </dependency>

We get the exact same unresolved dependency error.

So how are you supposed to deploy an artifact packaged as a bundle to a Maven repository, so that it can be used as a compile time dependency for another project?

Thanks

like image 611
Craig S. Dickson Avatar asked Nov 05 '22 14:11

Craig S. Dickson


1 Answers

The issue is that "3rdpartybundle.jar" is being built without setting extensions=true and/or supported types:

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
...
    <extensions>true</extensions>
...
    <configuration>
        <supportedProjectTypes>
            <supportedProjectType>jar</supportedProjectType>
            <supportedProjectType>war</supportedProjectType>
        </supportedProjectTypes>

If you can't fix that upstream, then there's a couple of options;

1) Repack it as a Jar using a new project pom:

                    <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-dependency-plugin</artifactId>
                            <version>2.3</version>
                            <configuration>
                                    <actTransitively>false</actTransitively>
                                    <outputDirectory>target/classes</outputDirectory>
                                    <artifactItems>
                                            <artifactItem>
                                                    <groupId>3rd</groupId>
                                                    <artifactId>party</artifactId>
                                                    <version>X.Y.Z</version>
                                            </artifactItem>
                                    </artifactItems>
                            </configuration>
                            <executions>
                                    <execution>
                                            <goals>
                                                    <goal>unpack</goal>
                                            </goals>
                                            <phase>compile</phase>
                                    </execution>
                            </executions>
                    </plugin>

2) Try using mvn deploy:deploy-file with -DgeneratePom=false -Dpackaging=jar -Dfile=/path/to/3rdpartybundle.jar but without specifying -DpomFile= - hope there's no META-INF/maven/pom.xml inside the 3rdpartybundle.jar - it should work using this but you'll need to specify the groupId/artifactId/version parameters as these won't be derived from the project's pom.

I know I've build bundle artifacts in the past and deployed these to our nexus (v1.9.0.1) and those in the Spring repo are typed bundle too, but don't recall any issue. (Incidentally you don't need to specify the bundle in dependency declarations, AFAIK if it's the only artifact it should be inferred)

like image 173
earcam Avatar answered Nov 09 '22 11:11

earcam