标签: maven-shade-plugin

包括非Mavenized依赖项,因此它适用于maven-shade-plugin

我想包括不使用Maven的GData Client作为我的Maven项目的依赖项.它作为一堆JAR文件发布.

另外,我使用Maven Shade Plugin构建一个没有任何外部依赖关系的可执行JAR(使用默认配置,不依赖于重命名/包含/排除/转换).

我怎样才能做到这一点?

(只是添加JAR作为资源不起作用,因为Shade插件必须提取它们).

dependencies maven-2 jar maven-shade-plugin

6
推荐指数
1
解决办法
3299
查看次数

过滤资源maven-shade-plugin

我正在尝试过滤我的jar中包含的资源.我正在使用shade-maven-plugin,这个将所有依赖项的所有资源添加到我生成的jar中,我只想包含我的项目资源.

这是我的pom定义:

    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>1.6</version>
            <executions>
                <execution>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <minimizeJar>true</minimizeJar>
                        <transformers>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>es.app.applet.MyApplet</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
            <configuration>
                <filters>
                    <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>META-INF/*.SF</exclude>
                            <exclude>META-INF/*.DSA</exclude>
                            <exclude>META-INF/*.RSA</exclude>
                            <exclude>META-INF/*.RSA</exclude>
                        </excludes>
                    </filter>
                </filters>
            </configuration>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

我尝试添加下一个过滤器以删除所有资源,然后添加另一个过滤器,仅添加我的artifactID资源,但它不起作用.

                    <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>resources/*.*</exclude>
                        </excludes>
                    </filter> <filter>
                        <artifact>my.groupId:my.artifactId</artifact>
                        <includes>
                            <include>resources/*.*</include>
                        </includes>
                    </filter>
Run Code Online (Sandbox Code Playgroud)

想法?

谢谢.

maven maven-shade-plugin

6
推荐指数
1
解决办法
4234
查看次数

无法用maven遮住罐子(INVOKESPECIAL/STATIC)

完整的错误消息:

无法执行目标org.apache.maven.plugins:maven-shade-plugin:2.3:项目阴影(默认) - :创建阴影jar时出错:接口上的INVOKESPECIAL/STATIC需要ASM 5 - > [帮助1]

我试图阴影的jarfile位于我自己的远程存储库中,使用sonatype nexus.这是我的pom配置:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.codelanx</groupId>
    <artifactId>phanaticprison</artifactId>
    <version>1.0.0</version>
    <name>PhanaticPrison</name>
    <packaging>jar</packaging>

    <repositories>
        <repository>
            <id>bukkit-repo</id>
            <url>http://repo.bukkit.org/content/repositories/public/</url>
        </repository>
        <repository>
            <id>codelanx-repo</id>
            <url>http://repo.codelanx.com/content/repositories/public/</url>
        </repository>
    </repositories>
    <licenses>
        <license>
            <name>Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International</name>
            <url>https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <artifactSet>
                        <includes>
                            <include>com.codelanx:codelanxlib</include>
                        </includes>
                    </artifactSet>
                    <minimizeJar>true</minimizeJar>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <targetPath>.</targetPath>
                <directory>${basedir}/src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <finalName>${project.name}</finalName>
    </build> …
Run Code Online (Sandbox Code Playgroud)

java eclipse netbeans maven maven-shade-plugin

6
推荐指数
1
解决办法
6671
查看次数

解决Java中的传递依赖冲突

我正在尝试构建一个与HBase通信的Dropwizard(Jersey)REST端点.虽然这些是我唯一的两个顶级依赖项,但这两个依赖项都加载了许多冲突的传递依赖项.这种冲突的一个简单例子是谷歌的番石榴:

  • HBase客户端指定版本11
  • Dropwizard指定18

Dropwizard不适用于版本11,HBase不适用于版本18.

我已经检查了Maven shade插件文档,但它似乎没有让你重新定位依赖jar中找到的类.所以我不知道如何解决这个问题,而不是将这两个组件分成单独的JVM.

java gradle maven maven-shade-plugin

6
推荐指数
1
解决办法
525
查看次数

maven shade插件定制变压器

鉴于maven shade插件资源转换器,我们如何创建自定义的?

我已经尝试将阴影插件添加到我的pom中:

<dependency>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.4.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

并创建一个实现ResourceTransformer的类.但是当我运行它时,我得到:

[错误]未能执行目标org.apache.maven.plugins:行家遮阳帘插件:2.4.1:灯罩(默认)上FOO项目:无法解析的魔力org.apache.maven.plugins的配置:行家荫-plugin:2.4.1:参数变换器的阴影:无法加载实现提示'test.transformer.TestTransformer' - > [帮助1]

变换器与我正在运行构建的项目在同一类路径上,我猜这是问题所在.有没有办法添加引入其他变形金刚的扩展?

java maven maven-shade-plugin

6
推荐指数
1
解决办法
1560
查看次数

如何使用commons-beanutils对beanutils依赖项进行重复数据删除?

我有一个具有多个依赖项的项目,最终导致依赖于以下各项(我从sbt-dependency-graph plugin中获得了这些依赖项):

  • commons-beanutils:commons-beanutils:1.7.0
  • commons-beanutils:commons-beanutils-core:1.8.0

因此,当我尝试使用sbt-assembly构建胖JAR时,它将失败,并出现以下重复数据删除错误:

[error] deduplicate: different file contents found in the following:
[error] /Users/someuser/.ivy2/cache/commons-beanutils/commons-beanutils/jars/someuser-beanutils-1.7.0.jar:org/apache/commons/beanutils/BasicDynaBean.class
[error] /Users/someuser/.ivy2/cache/commons-beanutils/commons-beanutils-core/jars/commons-beanutils-core-1.8.0.jar:org/apache/commons/beanutils/BasicDynaBean.class
Run Code Online (Sandbox Code Playgroud)

由于我需要两个依赖项,因此我尝试使用以下规则对其中之一进行着色:

ShadeRule.rename("org.apache.commons.beanutils.**" -> "shadedstuff.beanutils.@1").inLibrary("commons-beanutils" % "commons-beanutils" % "1.7.0").inAll
Run Code Online (Sandbox Code Playgroud)

但是然后我得到以下错误:

[error] deduplicate: different file contents found in the following:
[error] /Users/someuser/.ivy2/cache/commons-beanutils/commons-beanutils/jars/someuser-beanutils-1.7.0.jar:shadedstuff/beanutils/BasicDynaBean.class
[error] /Users/someuser/.ivy2/cache/commons-beanutils/commons-beanutils-core/jars/commons-beanutils-core-1.8.0.jar:shadedstuff/beanutils/BasicDynaBean.class
Run Code Online (Sandbox Code Playgroud)

好像对两个工件都应用了阴影处理。如何遮蔽特定的伪影?

dependencies sbt maven-shade-plugin sbt-assembly

6
推荐指数
1
解决办法
972
查看次数

使用maven-shade-plugin时出现依赖冲突怎么办?

我正在使用 maven-shade-plugin 创建一个可执行 jar,其中包含项目的所有依赖项。有时,这些依赖项会带来自己的依赖项,与其他库的依赖项发生冲突,并且 maven-shade-plugin 警告我不确定要在 uber jar 中包含哪个版本。

[WARNING] maven-shade-plugin has detected that some .class files
[WARNING] are present in two or more JARs. When this happens, only
[WARNING] one single version of the class is copied in the uberjar.
[WARNING] Usually this is not harmful and you can skeep these
[WARNING] warnings, otherwise try to manually exclude artifacts
[WARNING] based on mvn dependency:tree -Ddetail=true and the above
[WARNING] output
Run Code Online (Sandbox Code Playgroud)

一般来说,我对此警告的回应是使用<exclusions>pom 文件中依赖项声明的元素从我的项目中删除有问题的依赖项:

<!-- Amazon ElastiCache Client --> …
Run Code Online (Sandbox Code Playgroud)

dependencies maven maven-shade-plugin

6
推荐指数
1
解决办法
2494
查看次数

Apache Spark - 使用spark-submit抛出NoSuchMethodError

要将Spark应用程序提交到集群,他们的文档说明:

为此,请创建包含代码及其依赖项的程序集jar(或"uber"jar).sbt和Maven都有汇编插件.在创建程序集jar时,将Spark和Hadoop列为提供的依赖项; 这些不需要捆绑,因为它们是由集群管理器在运行时提供的.- http://spark.apache.org/docs/latest/submitting-applications.html

所以,我在我的pom.xml文件中添加了Apache Maven Shade插件.(版本3.0.0)
我将Spark依赖项的范围转换为provided.(版本2.1.0)

(我还添加了Apache Maven Assembly Plugin,以确保我在运行时将所有依赖项都包装在jar中mvn clean package.我不确定它是否真的有必要.)


这样就spark-submit失败了.它抛出一个NoSuchMethodError依赖我的(请注意,代码在IntelliJ内部编译时从本地实例工作,假设provided已删除).

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Stopwatch.createStarted()Lcom/google/common/base/Stopwatch;
Run Code Online (Sandbox Code Playgroud)

抛出错误的代码行是无关紧要的 - 它只是我的main方法中创建Stopwatch一部分Google Guava实用程序的第一行.(版本21.0)

在线的其他解决方案表明它与Guava的版本冲突有关,但我对这些建议还没有任何运气.任何帮助将不胜感激,谢谢.

java nosuchmethoderror guava maven-shade-plugin spark-submit

6
推荐指数
1
解决办法
1077
查看次数

在 Maven 中着色依赖项

我有两个通过 Maven 导入的依赖项,它们都导入了一个公共库,但版本不同,但版本彼此不兼容。基本上是这篇文章中描述的问题:

依赖树

但不幸的是,对我来说,解决方案并不像博文描述的那么简单,因为没有通用版本的包 Z适用于这两个依赖项。

跳过导致这一点的糟糕设计决策,因为我不控制这些库中的任何一个,我希望重新打包顶级依赖项之一并遮蔽其所有依赖项,以便它基本上可以使用自己的独立版本的 Z。这可以用 Maven 完成吗?

我考虑过的一个解决方案是隔离所有依赖于包的类,Y并将它们放在一个单独的应用程序中,然后将其作为导入的阴影jar进行传送X,但是我想知道是否有更简单的方法来实现这一点。

maven maven-shade-plugin

6
推荐指数
1
解决办法
3414
查看次数

maven-shade-plugin 是否适用于 Scala 类?

我有一个包含 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>```
Run Code Online (Sandbox Code Playgroud)

scala maven maven-shade-plugin scala-maven-plugin

6
推荐指数
1
解决办法
900
查看次数