有问题的错误消息是
[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包
mvnclean和mvncompile
工作正常。我的项目结构是
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>
而我的应用/我的应用核心/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>
maven-shade-plugin需要什么才能成功创建着色罐子?
编辑:将最小化Jar设置为错误可以解决我的问题,但为什么?有没有更好的方法,或者一种方法来获得最小化罐子的好处?
您现在可以使用最新版本的 maven-shade-plugin:3.2.0
自 13.0.2.2018 起,这将解决使用最小化Jar
(使用 JDK8)时出现的错误:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.0</version>
</plugin>
正如编辑中所说,将最小化Jar设置为假可以解决我的问题。
请看一下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>