我正在使用阴影来创建超级罐子。我重新定位了依赖类以避免冲突。但是,我找不到有关如何在 META-INF/versions 下重新定位类的在线文档。
我已经尝试过了,似乎有效。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<id>shade</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
...
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Multi-Release>true</Multi-Release>
</manifestEntries>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>META-INF/MANIFEST.MF</exclude>
<exclude>module-info.class</exclude>
</excludes>
</filter>
</filters>
<relocations>
...
<relocation>
<pattern>META-INF/versions/9/javax.xml.bind</pattern>
<shadedPattern>META-INF/versions/9/com.example.shaded.javax.xml.bind</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
也遇到这个问题,您可以尝试以下解决方案:
<relocations>
<relocation>
<pattern>org/apache/lucene</pattern>
<shadedPattern>org/apache/relocation/lucene/v811</shadedPattern>
<rawString>true</rawString>
</relocation>
</relocations>
将rawString属性设置为ture,并在pattern/shadedPattern属性中使用'/'(而不是'.')。
我找到了一个解决方法:使用
antrun
插件解压最终的 jar,手动移动 META-INF/versions
下的目录,然后重新打包 jar。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>repack</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<unzip src="${project.build.directory}/${project.build.finalName}.jar" dest="${project.build.directory}/tmp" />
<mkdir dir="${project.build.directory}/tmp/META-INF/versions/9/your/relocation/prefix" />
<move file="${project.build.directory}/tmp/META-INF/versions/9/org" todir="${project.build.directory}/tmp/META-INF/versions/9/your/relocation/prefix" />
<zip basedir="${project.build.directory}/tmp" destfile="${project.build.directory}/${project.build.finalName}.jar" />
<delete dir="${project.build.directory}/tmp" />
</target>
</configuration>
</execution>
</executions>
</plugin>