2013-07-24 30 views
12

到目前爲止,我使用Maven Assembly插件爲每個工件生成兩個JAR - 編譯源和依賴關係 - 原因很簡單 - 僅在網絡上部署編譯源比部署更快帶有40 MB數據的全功能於一身的JAR。Maven Shade插件生成兩個Jars

由於覆蓋內部文件,我不得不切換maven shade插件才能使用<transformers>功能。但是我管不了同時運行兩個處決:

<plugins> 
    <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-shade-plugin</artifactId> 
    <executions> 
     <execution> 
     <id>shade-libs</id> 
     <phase>package</phase> 
     <goals> 
      <goal>shade</goal> 
     </goals> 
     <configuration> 
      <outputFile>target/assembly/${project.artifactId}-libs.jar</outputFile> 
      <artifactSet> 
      <excludes> 
       <exclude>...</exclude> 
      </excludes> 
      </artifactSet> 
      <transformers> 
      <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
       <resource>META-INF/spring.handlers</resource> 
      </transformer> 
      <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
       <resource>META-INF/spring.schemas</resource> 
      </transformer> 
      </transformers> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin> 
    <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-shade-plugin</artifactId> 
    <executions> 
     <execution> 
     <id>shade-main</id> 
     <phase>package</phase> 
     <goals> 
      <goal>shade</goal> 
     </goals> 
     <configuration> 
      <outputFile>target/assembly/${project.artifactId}.jar</outputFile> 
      <artifactSet> 
      <includes> 
       <include>...</include> 
      </includes> 
      </artifactSet> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin> 
</plugins> 

當我運行mvn package,只有第二次執行運行。第一個總是被忽略。使用Maven組裝插件它完美地工作。

當然,解決方案可以同時使用匯編和陰影插件,但我希望找到更一致的解決方案。

+2

而不是定義插件兩次,你有沒有嘗試在一個插件定義中定義第二個'execution'而不是? – DB5

+0

如果您將其作爲答案發布,我會接受它。 –

+0

謝謝,現在已經完成了。很高興聽到它解決了你的問題。 – DB5

回答

21

而不是定義插件兩次,只需定義一次,但有兩個execution部分。所以在你的情況下,它會是:

<plugins> 
    <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-shade-plugin</artifactId> 
    <executions> 
     <execution> 
     <id>shade-libs</id> 
     <phase>package</phase> 
     <goals> 
      <goal>shade</goal> 
     </goals> 
     <configuration> 
      <outputFile>target/assembly/${project.artifactId}-libs.jar</outputFile> 
      <artifactSet> 
      <excludes> 
       <exclude>...</exclude> 
      </excludes> 
      </artifactSet> 
      <transformers> 
      <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
       <resource>META-INF/spring.handlers</resource> 
      </transformer> 
      <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
       <resource>META-INF/spring.schemas</resource> 
      </transformer> 
      </transformers> 
     </configuration> 
     </execution> 
     <execution> 
     <id>shade-main</id> 
     <phase>package</phase> 
     <goals> 
      <goal>shade</goal> 
     </goals> 
     <configuration> 
      <outputFile>target/assembly/${project.artifactId}.jar</outputFile> 
      <artifactSet> 
      <includes> 
       <include>...</include> 
      </includes> 
      </artifactSet> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin> 
</plugins>