Java 如何动态跳过maven antrun复制/着色:着色目标?
我使用maven配置由多个小型服务组成的应用程序。用java开发的大多数服务共享相同的maven配置,就像在相同的构建生命周期中一样,共享一些资源(比如SpringAMQP) 因此,我将共享的资源组织在一个超级内存中 虽然shade插件似乎并没有真正干扰安装过程,但是antrun插件当然找不到它应该复制的任何文件,因为shade插件没有创建任何jar文件 由于我希望shade/antrun插件的配置在SuperParam中被抽象,我需要跳过shade/copy目标 我尝试过Java 如何动态跳过maven antrun复制/着色:着色目标?,java,maven,maven-shade-plugin,maven-antrun-plugin,maven-lifecycle,Java,Maven,Maven Shade Plugin,Maven Antrun Plugin,Maven Lifecycle,我使用maven配置由多个小型服务组成的应用程序。用java开发的大多数服务共享相同的maven配置,就像在相同的构建生命周期中一样,共享一些资源(比如SpringAMQP) 因此,我将共享的资源组织在一个超级内存中 虽然shade插件似乎并没有真正干扰安装过程,但是antrun插件当然找不到它应该复制的任何文件,因为shade插件没有创建任何jar文件 由于我希望shade/antrun插件的配置在SuperParam中被抽象,我需要跳过shade/copy目标 我尝试过mvn clean安装
mvn clean安装-Dmaven.shade.skip=true
,mvn clean安装-Dmaven.copy.skip=true
,mvn clean安装-Dmaven.shade.shade.skip=true
下面是一个供您使用的小示例:
<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>Test</groupId>
<artifactId>SuperTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<log4j.version>1.2.17</log4j.version>
<destination>pleasedeleteme</destination>
<mainpackage>com.uk.cc.it.info.gov.test.xxx</mainpackage>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${mainpackage}.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${destination}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
</dependencies>
</project>
4.0.0
试验
超级测试
0.0.1-快照
聚甲醛
1.2.17
请删除我
com.uk.cc.it.info.gov.test.xxx
maven编译器插件
3.1
1.7
1.7
org.apache.maven.plugins
maven阴影插件
2.2
包裹
阴凉处
${mainpackage}.Main
org.apache.maven.plugins
maven依赖插件
2.8
复制
包裹
复制
${groupId}
${artifactId}
${version}
罐子
真的
${destination}
log4j
log4j
${log4j.version}
maven shade插件没有可跳过的选项。通常,shade插件不只是为了好玩,所以你可能想知道你是否真的想跳过这个。如果您认为它仍然有效,则必须创建一个激活配置文件,如下所示:
<activation>
<property>
<name>skipShade</name>
<value>!true</value>
</property>
</activation>
滑雪板
!真的
通过这种方式,它在默认情况下被激活,除非您添加
-DskipShade
或-DskipShade=true
您是否尝试在超级pom中将maven shade插件的阶段设置为“无”,然后在客户端pom中覆盖该阶段
因此,在父pom中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>shade</id>
<phase>none</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<!-- ... -->
</configuration>
</execution>
</executions>
</plugin>
org.apache.maven.plugins
maven阴影插件
2.3
阴凉处
没有一个
阴凉处
在需要它的儿童POM中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<!-- no need to specify version -->
<executions>
<execution>
<id>shade</id>
<phase>package</phase>
<!-- no need to specify configuration -->
</execution>
</executions>
</plugin>
org.apache.maven.plugins
maven阴影插件
阴凉处
包裹
Maven 3.6.1为您提供了一种新的方法
在SuperParam中,可以为着色配置定义轮廓:
<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>Test</groupId>
<artifactId>SuperTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<log4j.version>1.2.17</log4j.version>
<destination>pleasedeleteme</destination>
<mainpackage>com.uk.cc.it.info.gov.test.xxx</mainpackage>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${destination}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
</dependencies>
<profiles>
<profile>
<id>shade</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${mainpackage}.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
默认情况下,也可以通过传递-Pshade使用Jenkins的Jenkins文件激活该配置文件。它将覆盖maven.config设置。禁用使用-P!阴影
请注意,如果您在Intellij(2020.2.2)中使用maven.config文件,.mvn/maven.config文件必须存在于根聚合器pom文件夹的子目录中。在IDE中构建子项目表单目前不考虑子项目级别上的.mvn/maven.config文件。从subproject文件夹中的命令行运行mvn命令将同时检查子项目.mvn/maven.config和父项目.mvn/maven.config。禁用maven shade插件对我很有效。在我禁用Maven shade插件之前,该版本正在尝试生成减少依赖性的pom文件。尽管您的帖子很有帮助,但您是否愿意阅读我的帖子?我想将构建过程抽象为superpam,因为它对所有服务都是一样的。但是我不能安装SuperPom,因为我将shade/antrun插件包括在其中。需要明确的是:SuperPom只是其他人继承的单个pom文件。这里没有任何东西可以隐藏、打包或复制……现在是2021年,这里的帖子是2014年的,而《原著》的作者仍然是原著的作者,因为他奇怪地认为这是一种代码味道。所以下面的一个技巧是唯一的方法。没错,但是为每一个插件制作一个配置文件就像是用一把大锤做一个钉子。将其绑定到none阶段是很容易的。
<settings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<!-- toggle shading from inside Intellij IDEA -->
<profiles>
<profile>
<id>shade</id>
</profile>
</profiles>
<!-- Shade Profile has to be activeProfile to be
able to explicitly disable shading -->
<activeProfiles>
<activeProfile>shade</activeProfile>
</activeProfiles>
</settings>
-Pshading