【发布时间】:2018-09-07 11:09:36
【问题描述】:
有问题的错误信息是
[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 package。 mvn clean 和 mvn 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>
- 它比 升级版本 发现的 in this question 修复要晚得多
- 插件在子模块 pom 中,而不是在父 pom 中 错误 here
- 我尝试删除
<packaging>jar</packaging>无济于事。
maven-shade-plugin 需要什么才能成功创建阴影 jar?
编辑:将 minimizeJar 设置为 false 可以解决我的问题,但为什么呢?有没有更好的方法,或者获得最小化 jar 的好处的方法?
【问题讨论】:
-
请检查 maven-shade-plugin 版本 3.1.1 而不是 3.1.0...因为 3.1.1 中有针对 JDK 10 的明确修复...(mail-archive.com/announce@maven.apache.org/msg00837.html)跨度>
-
@khmarbaise 我按照你的建议升级了
标签: java maven maven-shade-plugin java-10