我尝试将maven-shade-plugin
用于模块化jar:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
<include>javax.xml.bind:jaxb-api</include>
<include>com.sun.xml.bind:jaxb-impl</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>javax.xml.bind</pattern>
<shadedPattern>org.update4j.javax.xml.bind</shadedPattern>
</relocation>
<relocation>
<pattern>com.sun.xml.bind</pattern>
<shadedPattern>org.update4j.com.sun.xml.bind</shadedPattern>
</relocation>
</relocations>
</configuration>
</plugin>
但是Maven会从警告罐中删除我的module-info.class
,并发出警告:
[WARNING] Discovered module-info.class. Shading will break its strong encapsulation.
如何配置它使其离开?
编辑:警告实际上是在删除有阴影的jar的模块描述符而不是我自己的模块描述符时发生的。
答案 0 :(得分:1)
由于JPMS世界中的模块信息决定了模块的公开程度,所以其中的阴影项可能会导致讨厌的“从两个不同的模块读取包装”错误。
我已经通过以下方式解决了
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<excludes>
<exclude>module-info.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
<executions>
<execution>
<id>add-module-infos</id>
<phase>package</phase>
<goals>
<goal>add-module-info</goal>
</goals>
<configuration>
<overwriteExistingFiles>true</overwriteExistingFiles>
<module>
<moduleInfoFile>
src/main/java/module-info.java
</moduleInfoFile>
</module>
</configuration>
</execution>
</executions>
</plugin>
这是一件非常烦人的事情,从我读过的所有内容来看,他们无意删除它或添加标志以绕过它。