我有一个相当典型的构建jar的pom.xml:
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mygroup</groupId>
<artifactId>my-lib</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>...</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>我认为从与jar一起部署的POM副本中删除测试依赖项(junit-jupiter及其依赖项)会更好,这样可以避免将它们强加给jar的用户。毕竟,测试代码不包含在已部署的jar中,因此测试是如何编写的对jar的用户来说应该无关紧要。
我认为这将是maven-shade-plugin的一个常见用例。但是在它的文档中似乎没有提到这个用例。而且我不能让shade插件从简化的POM中移除junit-jupiter依赖。
有没有一种直接的方法可以从已部署的POM中移除依赖项?我什么都不担心吗?
我看到了this question,但它似乎是要从uber jar中删除测试依赖内容。在我的例子中,我实际上并不是在创建一个超级jar。我只是尝试使用shade插件来重写POM。
发布于 2020-07-07 23:39:15
如果你想从部署的POM中删除不必要的部分,你可以使用flatten maven插件:
https://www.mojohaus.org/flatten-maven-plugin/flatten-mojo.html
其中一个功能是删除测试依赖项。
https://stackoverflow.com/questions/62778744
复制相似问题