2

私は maven-shade-plugin を使用して、2 つの別々の jar を 1 つの結合 jar に結合しています。

jar の 1 つは署名されていますが、もう 1 つは署名されていません。

プラグインのデフォルト構成を使用すると、署名に必要なダイジェストが新しいマニフェストにないため、壊れた jar が作成されます。

署名ファイルを除外することで jar を「修正」することもできますが、これはもちろん、完全に署名されていない jar になります。

署名されたすべてのクラスが署名され有効なままの結合された jar を作成する方法を探しています。- jar 形式では、この種の jar を使用できますが、shade プラグインにそうするように指示する簡単な方法が見つかりませんでした。

マニフェスト ファイルを適切にマージするには、独自のトランスフォーマーを作成する必要がありますか?それとも、まだ見つからなかったシェード プラグインに適切なオプションが既にありますか?


例:

pom.xml (2 つのモジュール "foo" と "bar" を定義)

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

foo/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>
  <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>

bar/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>

両方のモジュールに 1 つの hello-word クラスが含まれている場合、私は機能し、署名されたクラスの存在について通知することを期待java -jar foo/target/foo-1.0.jarします。jarsigner -verify foo/target/foo-1.0.jar

4

1 に答える 1