2014-09-11 115 views
1

我正在使用maven-shade-plugin將兩個獨立的瓶子合併成一個組合的罐子。如何告訴maven-shade-plugin保存簽名?

其中一個罐子是簽名的,而另一個則不是。

如果我使用插件的默認配置,它將構建一個損壞的jar,因爲新清單缺少簽名所需的摘要。

我可以通過排除簽名文件來「修復」jar,但是這當然會導致完全未簽名的jar。

我正在尋找一種方法來創建一個組合的jar與所有簽名類仍然簽署和有效。 - jar格式允許使用那些罐子,但我找不到一個簡單的方法告訴陰影插件這樣做。

我應該寫自己的變換器來完成清單文件的合適合併,還是在陰影插件中已經有一個合適的選項,但我沒有找到它?


實施例:

的pom.xml(定義兩個模塊 「foo」 和 「棒」)

<?xml version="1.0"?> 
<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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>mygroup</groupId> 
    <artifactId>myparent</artifactId> 
    <packaging>pom</packaging> 
    <version>1.0</version> 
    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 
    <modules> 
    <module>foo</module> 
    <module>bar</module> 
    </modules> 
    <build> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-jar-plugin</artifactId> 
     <version>2.4</version> 
     <configuration> 
      <archive> 
      <addMavenDescriptor>false</addMavenDescriptor> 
      </archive> 
     </configuration> 
     </plugin> 
    </plugins> 
    </build> 
</project> 

富/ pom.xml中:(結合簽名欄成無符號的富)

<?xml version="1.0"?> 
<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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <parent> 
    <groupId>mygroup</groupId> 
    <artifactId>myparent</artifactId> 
    <version>1.0</version> 
    </parent> 
    <artifactId>foo</artifactId> 
    <dependencies> 
    <dependency> 
     <groupId>mygroup</groupId> 
     <artifactId>bar</artifactId> 
     <version>1.0</version> 
    </dependency> 
    </dependencies> 
    <build> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-shade-plugin</artifactId> 
     <version>2.3</version> 
     <executions> 
      <execution> 
      <phase>package</phase> 
      <goals> 
       <goal>shade</goal> 
      </goals> 
      <configuration> 
       <transformers> 
       <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
        <manifestEntries> 
        <Main-Class>Foo</Main-Class> 
        </manifestEntries> 
       </transformer> 
       </transformers> 
      </configuration> 
      </execution> 
     </executions> 
     </plugin> 
    </plugins> 
    </build> 
</project> 

酒吧/ pom.xml中:(創建簽署巴)

<?xml version="1.0"?> 
<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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <parent> 
    <groupId>mygroup</groupId> 
    <artifactId>myparent</artifactId> 
    <version>1.0</version> 
    </parent> 
    <artifactId>bar</artifactId> 
    <build> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-jarsigner-plugin</artifactId> 
     <version>1.3.2</version> 
     <configuration> 
      <keystore>${user.home}/keystore-name</keystore> 
      <alias>alias-name</alias> 
      <storepass>123456</storepass> 
     </configuration> 
     <executions> 
      <execution> 
      <id>sign</id> 
      <goals> 
       <goal>sign</goal> 
      </goals> 
      </execution> 
      <execution> 
      <id>verify</id> 
      <goals> 
       <goal>verify</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 
    </plugins> 
    </build> 
</project> 

如果兩個模塊都包含單個hello-word類,我期望java -jar foo/target/foo-1.0.jar可以工作,jarsigner -verify foo/target/foo-1.0.jar可以告訴我們簽名類的存在。

回答

2

maven樹蔭插件不能很好地與簽名的罐子玩。我會建議你看看Capsule的方式更好做這種工作。

相關問題