我有一个同时包含Java和Scala组件的maven项目,但是当我使用maven-shade-plugin时,它会重新定位Java和Scala文件的包名称,但只重命名Java文件中的包,Scala文件仍然包含较旧的包名称,我遗漏了什么?
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<!--<minimizeJar>true</minimizeJar>-->
<artifactSet>
<includes>
<include>ml.dmlc:xgboost4j-spark</include>
<include>ml.dmlc:xgboost4j</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>ml.dmlc.xgboost4j</pattern>
<shadedPattern>ml.dmlc.xgboost4j.shaded</shadedPattern>
</relocation>
</relocations>
<transformers>
</transformers>
</configuration>
</execution>
</executions>
</plugin>```发布于 2020-12-29 13:13:42
可悲的是,我相信Maven本打算具有此功能,但目前(2020年12月)还没有。
这可以通过这个错误标签看到:https://issues.apache.org/jira/browse/MSHADE-345
解决方法
我个人为此做了一个愚蠢的变通办法。我创建了一个新的空mvn项目,它具有以下依赖关系:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.0-jre</version>
</dependency>和插件:
<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>
<configuration>
<relocations>
<relocation>
<pattern>com.google.</pattern>
<shadedPattern>shader.com.google.</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>然后,在包含需要低版本的guava和新版本的guava的代码的项目中,将空项目作为依赖项包括在内。
<dependency>
<groupId>com.yoursite.yourwork</groupId>
<artifactId>shader</artifactId>
<version>0.0.1</version>
</dependency>然后在.scala文件中导入新的(版本28)芭乐类,如下所示:
import shader.com.google.common.graph.Network为什么这样做?
由于该错误只发生在scala项目中,当您引用使用依赖项的自己的类时,或者正如问题中所说的“Scala文件仍然包含较旧的包名”中所说的那样,对不引用其自身依赖项的项目进行着色可以绕过该错误。
发布于 2019-03-23 11:25:05
是的,确实如此。选择您想要的任何build version,并将库导入到Scala项目中。
https://stackoverflow.com/questions/55309684
复制相似问题