gpt4 book ai didi

scala - Maven-shade-plugin是否可以与scala类一起使用?

转载 作者:行者123 更新时间:2023-12-03 15:03:13 30 4
gpt4 key购买 nike

我有一个同时包含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>```

最佳答案

可悲的是,我相信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) Guava 类,如下所示:
import shader.com.google.common.graph.Network
为什么有效
由于该错误仅发生在引用您自己的使用依赖项的类的scala项目中,或者如问题 “Scala文件仍包含较早的程序包名称” 所述,请为未引用其依赖项的项目加上阴影绕过该错误。

关于scala - Maven-shade-plugin是否可以与scala类一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55309684/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com