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

问题描述 投票:7回答:1

我尝试将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的模块描述符而不是我自己的模块描述符时发生的。

java maven java-9 maven-shade-plugin java-module
1个回答
1
投票

由于JPMS世界中的模块信息决定了模块的公开程度,其中的阴影项可能会导致讨厌的“从两个不同的模块读取包装”错误。

我已经通过以下方式解决了它

  • 隐藏,过滤掉所有模块中的模块信息
  • 然后添加module-info(可能有效或无效,谢谢修改,您不知道这有多有用)
  <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>

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

© www.soinside.com 2019 - 2024. All rights reserved.