3

I'm trying to package an OSGi bundle with it's dependencies builtin. I'm using maven-shade-plugin 2.3 for including some dependencies, but it fails during packaging stage with the following error:

[ERROR] The project main artifact does not exist. This could have the following
[ERROR] reasons:
[ERROR] - You have invoked the goal directly from the command line. This is not
[ERROR]   supported. Please add the goal to the default lifecycle via an
[ERROR]   <execution> element in your POM and use "mvn package" to have it run.
[ERROR] - You have bound the goal to a lifecycle phase before "package". Please
[ERROR]   remove this binding from your POM such that the goal will be run in
[ERROR]   the proper phase.
[ERROR] - You removed the configuration of the maven-jar-plugin that produces the main artifact.

Here is how my project's pom looks like:

<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>ru.multicabinet.plugin</groupId>
<artifactId>testArtifact</artifactId>
<version>1.0-SNAPSHOT</version>

<packaging>bundle</packaging>

<dependencies>
    <dependency>
        <groupId>org.osgi</groupId>
        <artifactId>org.osgi.core</artifactId>
        <version>4.3.1</version>
    </dependency>
    <dependency>
        <groupId>org.osgi</groupId>
        <artifactId>org.osgi.compendium</artifactId>
        <version>4.3.1</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.4</version>
    </dependency>
    <dependency>
        <groupId>org.apache.felix</groupId>
        <artifactId>org.apache.felix.scr.annotations</artifactId>
        <version>1.9.6</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.7</version>
    </dependency>
    <dependency>
        <groupId>javax.activation</groupId>
        <artifactId>activation</artifactId>
        <version>1.1.1</version>
    </dependency>

</dependencies>

<build>
    <plugins>

        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-scr-plugin</artifactId>
            <version>1.15.0</version>
            <executions>
                <execution>
                    <id>generate-scr-scrdescriptor</id>
                    <goals>
                        <goal>scr</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>

            <configuration>
                <remoteOBR>obr-repo</remoteOBR>
                <instructions>
                    <Bundle-Description>Test Plugin</Bundle-Description>
                    <Import-Package>
                        org.osgi.framework,
                        javax.net.ssl,
                        javax.mail,
                        javax.mail.internet,
                        javax.activation
                    </Import-Package>
                    <Bundle-SymbolicName>ru.multicabinet.plugin.license.testArtifact</Bundle-SymbolicName>
                </instructions>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <execution>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <artifactSet>
                            <includes>
                                <include>commons-codec:commons-codec</include>
                            </includes>
                        </artifactSet>
                    </configuration>
                </execution>
            </executions>
        </plugin>

    </plugins>
</build>


</project>

I suspect that I'm getting this error because I'm using "bundle" packaging type, so shade plugin not recognizing there is an actual jar file and therefore complaining about main artifact. How this can be resolved?

Thanks

Artem Zhirkov
  • 157
  • 12
  • If you like to shade a package you need to make a separate module where you can create a shaded variant of it but not as you already realized in module where packaging is bundle. – khmarbaise Jul 07 '15 at 08:16
  • @khmarbaise but this separate package will be missing all osgi metadata in it since it won't be a bundle, so it won't be useful for me. I'm looking for a way to make it both a valid OSGi bundle and a include every dependency I need. – Artem Zhirkov Jul 07 '15 at 08:27

1 Answers1

0

I managed to solve this by changing packaging type of the project back to "jar" and configuring maven bundle plugin to inject osgi metadata to the final jar artifact without having to use "bundle" packaging as it is described in maven bundle plugin documentation.

Example maven bundle plugin configuration for injecting OSGi metadata into jar packages:

<plugin>
  <artifactId>maven-jar-plugin</artifactId>
  <configuration>
    <archive>  
     <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
    </archive> 
  </configuration>
</plugin>  
<plugin>   
   <groupId>org.apache.felix</groupId>
   <artifactId>maven-bundle-plugin</artifactId>
   <executions>
     <execution>
     <id>bundle-manifest</id>
     <phase>process-classes</phase>
     <goals>    
       <goal>manifest</goal>
     </goals>   
     </execution>
   </executions>
</plugin>
Artem Zhirkov
  • 157
  • 12