maven-shade-plugin и нестандартный тип упаковки

Я пытаюсь упаковать пакет OSGi со встроенными зависимостями. Я использую maven-shade-plugin 2.3 для включения некоторых зависимостей, но на этапе упаковки происходит сбой со следующей ошибкой:

[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.

Вот как выглядит pom моего проекта:

<?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>

Я подозреваю, что я получаю эту ошибку, потому что я использую тип упаковки «пакет», поэтому плагин тени не распознает наличие фактического файла jar и, следовательно, жалуется на основной артефакт. Как это можно решить?

Спасибо


person Artem Zhirkov    schedule 07.07.2015    source источник
comment
Если вы хотите затенить пакет, вам нужно сделать отдельный модуль, где вы можете создать его затененный вариант, но не так, как вы уже поняли в модуле, где упаковка является пакетом.   -  person khmarbaise    schedule 07.07.2015
comment
@khmarbaise, но в этом отдельном пакете будут отсутствовать все метаданные osgi, поскольку он не будет пакетом, поэтому он мне не пригодится. Я ищу способ сделать его действительным пакетом OSGi и включить все необходимые мне зависимости.   -  person Artem Zhirkov    schedule 07.07.2015


Ответы (1)


Мне удалось решить эту проблему, изменив тип упаковки проекта обратно на «jar» и настроив плагин пакета maven для внедрения метаданных osgi в окончательный артефакт jar без необходимости использовать упаковку «bundle», как это описано в документация по плагину пакета maven.

Пример конфигурации плагина пакета maven для внедрения метаданных OSGi в пакеты jar:

<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>
person Artem Zhirkov    schedule 07.07.2015