为什么Maven Shade插件会删除module-info.class?

Mor*_*hai 7 java maven maven-shade-plugin java-9 java-module

我尝试将其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>
Run Code Online (Sandbox Code Playgroud)

但是Maven会module-info.class从阴影罐中删除我,并发出警告:

[WARNING] Discovered module-info.class. Shading will break its strong encapsulation.
Run Code Online (Sandbox Code Playgroud)

我如何配置它离开它?

编辑:警告实际上是在删除阴影jar的模块描述符而不是我自己的模块描述符时发生的。

Mar*_*gon 5

由于 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>
Run Code Online (Sandbox Code Playgroud)

这是一件非常烦人的事情,从我读过的所有内容来看,他们无意删除它或添加一个标志来绕过它。