我尝试将maven-shade-plugin
用于模块化罐子:
<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.
如何配置它以离开它?
编辑:警告实际上发生在它删除阴影罐的模块描述符时,而不是我自己的。
由于JPMS世界中的模块信息决定了模块的公开,因此阴影项目可能会导致令人讨厌的"从两个不同的模块读取包"错误。
我已经通过以下方式解决了它
- 着色,过滤掉所有模块中的模块信息
- 然后添加模块信息(可能有效,也可能无效,谢谢修改,你不知道这有多大用处(
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<artifactSet>
<excludes>
<exclude>module-info.java</exclude>
</excludes>
</artifactSet>
</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>
这是一件非常烦人的事情,从我读到的所有内容来看,他们无意删除它或添加一个标志来绕过它。