如何阻止特定maven-jar-plugin执行产物被安装/部署?
如何让Maven仅在target目录生成额外的test-jar而不安装/部署?
你只需要在maven-jar-plugin对应execution的configuration中添加<attach>false</attach>配置项,就能阻止这个额外的JAR被安装到本地仓库或部署到远程仓库,只会留在你指定的target子目录里。
修改后的完整POM配置如下:
<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.me</groupId> <artifactId>my-artifact</artifactId> <packaging>jar</packaging> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <executions> <execution> <id>some-other-sources</id> <phase>process-test-classes</phase> <goals> <goal>test-jar</goal> </goals> <configuration> <testClassesDirectory>${project.build.directory}/some-other-sources</testClassesDirectory> <outputDirectory>${project.build.directory}/some-other-sources</outputDirectory> <classifier>some-other-sources</classifier> <!-- 添加该配置阻止JAR被纳入仓库同步流程 --> <attach>false</attach> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
原理说明
maven-jar-plugin的attach参数默认值为true,意味着生成的JAR会作为项目附属构件,参与后续install、deploy等阶段。将其设为false后,这个JAR就只会作为临时产物保留在指定的输出目录,不会被Maven同步到本地或远程仓库。
内容的提问来源于stack exchange,提问作者JackPGreen
相关产品推荐
相关产品推荐

