2

MANIFEST.MFjar パッケージ化されたアーティファクトと test-jar-packaged 用に異なるファイルを作成しようとしています。に追加のmaven-jar-pluginものを追加するために使用されているMANIFEST.MF- これまでのところ完全に機能します。しかし、テストプロジェクト用に別のテンプレート ファイルを選択したい場合MANIFEST.MF、Maven は両方のアーティファクトに対して 2 番目に参照されるテンプレートのみを使用します...

PROD-MANIFEST.MF-templateMaven で を通常の jar-packaging とTEST-MANIFEST.MF-templateを test-jar-packagingに使用するにはどうすればよいですか?

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
            <execution>
                <id>test-manifest-mf</id>
                <phase>package</phase>
                <goals>
                    <goal>test-jar</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <archive>
                <manifest>
                    <addClasspath>true</addClasspath>
                </manifest>
                <manifestFile>foo/TEST-MANIFEST.MF</manifestFile>
            </archive>
        </configuration>
    </plugin>

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
            <execution>
                <id>default-manifest-mf</id>
                <phase>package</phase>
                <goals>
                    <goal>jar</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <archive>
                <manifest>
                    <addClasspath>true</addClasspath>
                </manifest>
                <manifestFile>foo/PROD-MANIFEST.MF</manifestFile>
            </archive>
        </configuration>
    </plugin>
4

2 に答える 2

1

提供した各プラグイン構成をプロファイルにラップします。

<profiles>
  <profile>
    <id>PROD</id>
    <build>
      <plugins>
        // your PROD plugin configuration
      </plugins>
    </build>
  </profile>
  <profile>
    <id>TEST</id>
    <build>
      <plugins>
        // your TEST plugin configuration
      </plugins>
    </build>
  </profile>
</profiles>

次に、プロファイルを使用して Maven を呼び出します

mvn package -P PROD

それが役立つことを願っています。

于 2011-11-21T17:25:44.933 に答える
1

これを試して:

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <executions>
      <execution>
        <id>test-manifest-mf</id>
        <phase>package</phase>
        <goals>
            <goal>test-jar</goal>
        </goals>
        <configuration>
          <archive>
            <manifest>
                <addClasspath>true</addClasspath>
            </manifest>
            <manifestFile>foo/TEST-MANIFEST.MF</manifestFile>
          </archive>
        </configuration>
      </execution>

      <execution>
        <id>default-manifest-mf</id>
        <phase>package</phase>
        <goals>
            <goal>jar</goal>
        </goals>
        <configuration>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
            </manifest>
            <manifestFile>foo/PROD-MANIFEST.MF</manifestFile>
          </archive>
        </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>

この構成は、同じプラグインの 2 つの異なる実行を実行しており、それぞれに独自のアーカイブ構成があります。

次のように、実行の外部で構成されたアーカイブを持つ親 pom が階層内のどこかにある場合:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <configuration>
    <archive>
       ... other archive config ...
    </archive>
  </configuration>
</plugin>

その構成は、デフォルトで持っているものとマージされます。それが発生したくない場合は、次combine.selfのように属性を<archive>要素に追加します。

<archive combine.self="override">

POM リファレンスのプラグイン セクションで説明されているとおりです。

于 2012-02-25T01:01:25.873 に答える