shade for parameter resource: Cannot find 'resource' in class org.apache.maven.plugins.shade.resource.ManifestResourceTransformer

后端 未结 3 429
离开以前
离开以前 2021-01-11 10:51

I\'m working on a maven project. I\'m trying to integrate jmh benchmarking into my project. The pom.xml of my maven project...


    

        
相关标签:
3条回答
  • 2021-01-11 11:29

    Found a cause of this affecting my own setup and am sharing here in case it helps others.

    In my case, the cause is a parent pom containing the maven-shade-plugin configuration as well as my own pom. The way that Maven merges these works out incorrectly. It appears the Maven is matching the transformer tags in the order they appear and merging them.

    To figure this out, use mvn help:effective-pom and look for the resulting maven-shade-plugin configuration. In my case, a <resource> tag was added to the ManifestResourceTransformer, and this resource matched the first entry in the parent pom's maven-shade-plugin configuration.

    Adding an <id> to the <execution> eliminates the problem:

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

    I suspect both configurations were using the same, default ID. So the key is that each execution of the plugin have a unique id.

    0 讨论(0)
  • 2021-01-11 11:45

    The ManifestResourceTransformer allows existing entries in the MANIFEST to be replaced and new entries added.

    For example, the following sample sets

    • the Main-Class entry to the value of the app.main.class property,
    • the X-Compile-Source-JDK entry to the value of the maven.compile.source property and
    • the X-Compile-Target-JDK entry to the value of the maven.compile.target property.

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

    I think this is the right Configuration

    0 讨论(0)
  • 2021-01-11 11:45

    Your configuration looks wrong:

    <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>
    
    0 讨论(0)
提交回复
热议问题