Maven-shade-plugin and custom packaging type

I am trying to package an OSGi package with its built-in dependencies. I am using maven-shade-plugin 2.3 to include some dependencies, but it fails in the packaging step 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.

      

This is how my pom project 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 I am getting this error because I am using the "bundle" packaging type, so the tinted plugin does not recognize the actual jar file and therefore complains about the main artifact. How can this be solved?

thank

+3


source to share


1 answer


I managed to solve this problem by changing the project packaging type to "jar" and configuring the maven bundle plugin to insert the osgi metadata into the latest jar artifact without having to use the "bundle" packaging as described in the maven bundle plugin documentation .

Example maven 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>

      

0


source







All Articles