在 Maven Shade 插件中包含依赖项

3

我正在尝试创建一个可部署的jar文件,其中使用了Apache的commons-lang3库。然而,我的AWS集群没有这个库,所以我遇到了类NotFoundException的问题。我想我需要手动添加依赖项,但是我在使用maven shade插件时遇到了问题(有人建议我使用它)。我的当前pom文件如下:

    <dependency>
        <groupId>org.apache.pig</groupId>
        <artifactId>pig</artifactId>
        <version>0.12.0-cdh5.2.6</version>
    </dependency>

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.4</version>
    </dependency>
    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <artifact>org.apache.commons:commons-lang3</artifact>
                                <includes>
                                    <include>org/apache/commons/commons-lang3/3.4/*</include>
                                </includes>
                        <minimizeJar>true</minimizeJar>
                    </configuration>
                </execution>
            </executions>

        </plugin>

我想要一个完全正常的jar包,并嵌入commons-lang3库。我是不是做错了什么?


根据 https://maven.apache.org/plugins/maven-shade-plugin/shade-mojo.html - 你应该在 <configuration> 中使用 <artifactSet> 而不是 <artifact>... 看起来不支持 artifact。 - Roman Zenka
1个回答

5
为了包含白名单jar包,您需要执行以下操作:
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <artifactSet>
                            <includes>
                                <include>org.apache.commons:commons-lang3</include>
                            </includes>
                        </artifactSet>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

1
我发现 org.apache.commons:commons-lang3 的 pom 依赖没有被包含。它只添加了 org.apache.commons:commons-lang3 而不是它的传递依赖。 - Madhav Kumar Jha

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接