2

我正在尝试MANIFEST.MF为 jar-packaged 工件和 test-jar-packaged 创建不同的文件。maven-jar-plugin用于将其他东西添加到-MANIFEST.MF到目前为止效果很好。但是,如果我想MANIFEST.MF为 testproject 选择不同的模板文件,Maven 只对两个工件使用第二个引用的模板......

我怎样才能让 Maven 使用PROD-MANIFEST.MF-template普通的 jar-packaging 和TEST-MANIFEST.MF-templatetest-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

尝试这个:

<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 回答
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 回答