java Maven shade插件无法执行目标?

inn6fuwd  于 2023-04-19  发布在  Java
关注(0)|答案(4)|浏览(201)

有问题的错误消息是

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

myapp-core文件夹中的mvn packagemvn cleanmvn compile工作正常。我的项目结构是

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

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

myapp/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>
  • 这是一个比 upgrade the version fix found in this question晚得多的版本
  • 插件在子模块pom中,而不是父pom中,错误是here
  • 我试过删除<packaging>jar</packaging>,但无济于事。

maven-shade-plugin需要什么才能成功创建着色的jar?

编辑:将minimizeJar设置为false解决了我的问题,但为什么呢?有更好的方法吗?或者有一种方法可以获得最小化jar的好处?

p4rjhz4m

p4rjhz4m1#

你现在可以使用latest release maven-shade-plugin:3.2.0 as of 13.09.2018来解决使用minimizeJar(使用JDK8+)时的错误:

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

yh2wf1be2#

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

c9qzyr3d

c9qzyr3d3#

请看一下Maven的教程:https://maven.apache.org/plugins/maven-shade-plugin/usage.html
插件的配置在过去有一些变化,你不需要指定转换。
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>
xqnpmsa8

xqnpmsa84#

我可以通过升级到最新的插件版本来解决这个问题

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

相关问题