参数资源的阴影:在类org.apache.maven.plugins.shade.resource.ManifestResourceTransformer中找不到'资源'

时间:2017-04-26 06:42:15

标签: maven benchmarking microbenchmark jmh

我正在研究一个maven项目。我正在尝试将jmh基准测试集成到我的项目中。我的maven项目的pom.xml ......

<parent>
    <groupId>platform</groupId>
    <artifactId>platform-root</artifactId>
    <version>3.0-SNAPSHOT</version>
    <relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>platform-migration</artifactId>
<packaging>jar</packaging>
<name>Platform Migration</name>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compile.source>1.7</maven.compile.source>
    <maven.compile.target>1.7</maven.compile.target>
    <jmh.version>1.1.1</jmh.version>
    <jersey-version>2.22.1</jersey-version>
    <uberjar.name>rest-benchmarks</uberjar.name>
</properties>


<dependencies>
    <dependency>
        <groupId>platform</groupId>
        <artifactId>platform-commons</artifactId>
        <version>${platform.version}</version>
    </dependency>

    <dependency>
        <groupId>platform</groupId>
        <artifactId>platform-persistence</artifactId>
        <version>${platform.version}</version>
    </dependency>

    <dependency>
        <groupId>platform</groupId>
        <artifactId>platform-testing</artifactId>
        <version>${project.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.openjdk.jmh</groupId>
        <artifactId>jmh-core</artifactId>
        <version>${jmh.version}</version>
    </dependency>
    <dependency>
        <groupId>org.openjdk.jmh</groupId>
        <artifactId>jmh-generator-annprocess</artifactId>
        <version>${jmh.version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-client</artifactId>
        <version>${jersey-version}</version>
    </dependency>

</dependencies>


<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
                <execution>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>org.openjdk.jmh.Main</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

当我使用“mvn clean install”构建项目时,出现以下错误

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:3.0.0:shade (default) on project platform-migration: Unable to parse configuration of mojo org.apache.maven.plugins:maven-shade-plugin:3.0.0:shade for parameter resource: Cannot find 'resource' in class org.apache.maven.plugins.shade.resource.ManifestResourceTransformer -> [Help 1]

我不明白为什么会发生这种错误?

3 个答案:

答案 0 :(得分:0)

您的配置看起来不对:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
          <execution>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <manifestEntries>
                    <Main-Class>xxxxxxxxxxx</Main-Class>
                  </manifestEntries>
                </transformer>
              </transformers>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>

答案 1 :(得分:0)

ManifestResourceTransformer 允许替换 MANIFEST 中的现有条目并添加新条目。

例如,以下示例集

  • 指向app.main.class属性值的Main-Class条目
  • X-Compile-Source-JDK条目到maven.compile.source属性的值和
  • X-Compile-Target-JDK条目到maven.compile.target属性的值。

<project>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
          <execution>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <manifestEntries>
                    <Main-Class>${app.main.class}</Main-Class>
                    <X-Compile-Source-JDK>${maven.compile.source}</X-Compile-Source-JDK>
                    <X-Compile-Target-JDK>${maven.compile.target}</X-Compile-Target-JDK>
                  </manifestEntries>
                </transformer>
              </transformers>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

我认为这是正确的配置

答案 2 :(得分:0)

找到了影响我自己设置的原因,并在此处分享以防他人使用。

对于我来说,原因是包含maven-shade-plugin配置以及我自己的pom的父pom。 Maven合并这些文件的方式无法正确解决。看来Maven依序匹配transformer标签并合并它们。

要弄清楚这一点,请使用mvn help:effective-pom并查找生成的maven-shade-plugin配置。就我而言,<resource>标签被添加到ManifestResourceTransformer,并且此资源与父pom maven-shade-plugin配置中的第一项匹配。

<id>上添加<execution>可以解决此问题:

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <executions>
      <execution>
        <id>shade-my-jar</id>
...

我怀疑这两种配置都使用相同的默认ID。因此,关键在于插件的每次执行都具有唯一的ID。