简体   繁体   English

Maven shade 插件未能执行目标?

[英]Maven shade plugin failed to execute goal?

There error message in question is有问题的错误消息是

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:3.1.0:shade (default) on project myapp-core: Error creating shaded jar: null: IllegalArgumentException -> [Help 1]

from mvn package in the myapp-core folder.来自myapp-core文件夹中的mvn package mvn clean and mvn compile work fine. mvn cleanmvn compile工作正常。 My project structure is我的项目结构是

myapp/
    myapp-acceptance-tests/
    myapp-core/
        pom.xml
    pom.xml

And myapp/pom.xml is defined bymyapp/pom.xml

<groupId>com.myself.myapp</groupId>
<artifactId>myapp</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
    <module>myapp-core</module>
    <module>myapp-acceptance-tests</module>
</modules>

<properties>
    <maven.compiler.source>10</maven.compiler.source>
    <maven.compiler.target>10</maven.compiler.target>
</properties>

<dependencies>
    ...
</dependencies>

And myapp/myapp-core/pom.xml is defined bymyapp/myapp-core/pom.xml

<artifactId>myapp-core</artifactId>
<packaging>jar</packaging>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>myself.myapp.Main</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>10</source>
                <target>10</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <server>mytomcat7</server>
                <path>/</path>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.1.0</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <shadedArtifactAttached>true</shadedArtifactAttached>
                        <shadedClassifierName>shaded</shadedClassifierName>
                        <minimizeJar>true</minimizeJar>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
  • It is a much later version than the upgrade the version fix found in this question它比升级此问题中找到的版本修复程序要晚得多
  • the plugin is in the submodule pom rather than the parent pom as is the mistake here插件在子模块 pom 中,而不是在父 pom 中,这是这里的错误
  • and I have tried removing <packaging>jar</packaging> to no avail.我尝试删除<packaging>jar</packaging>无济于事。

What does maven-shade-plugin need to successfully create the shaded jar? maven-shade-plugin 需要什么才能成功创建阴影 jar?

EDIT: setting minimizeJar to false solves my problem, but why?编辑:将minimizeJar 设置为false 可以解决我的问题,但为什么呢? Is there a better way, or a way to get the benefits of a minimised jar?有没有更好的方法,或者一种方法来获得最小化 jar 的好处?

You can now use the latest release maven-shade-plugin:3.2.0 as of 13.09.2018 which shall solve the error while using minimizeJar (with JDK8+) :现在,您可以使用最新版本maven-shade-plugin:3.2.0截至2018年9月13日,而使用它应解决错误minimizeJar (与JDK8 +):

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-shade-plugin</artifactId>
  <version>3.2.0</version>
</plugin>

正如编辑中所说,将minimizeJar 设置为false 解决了我的问题

Please take a look at this tutorial from Maven: https://maven.apache.org/plugins/maven-shade-plugin/usage.html请看一下Maven的这个教程: https : //maven.apache.org/plugins/maven-shade-plugin/usage.html

The configuration of the plugin changed a bit over past and you don't need to specify the transformations.插件的配置在过去发生了一些变化,您不需要指定转换。

An example looks like this for 3.2.1: 3.2.1 的示例如下所示:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.2.1</version>
        <configuration>
          <!-- put your configurations here -->
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM