gpt4 book ai didi

java - 如何跳过 maven antrun copy/shade :shade goal dynamically?

转载 作者:搜寻专家 更新时间:2023-11-01 01:34:19 26 4
gpt4 key购买 nike

我正在使用 maven 来配置由多个小型服务组成的应用程序。大多数用 java 开发的服务共享相同的 maven 配置,如在相同的构建生命周期中,一些共享资源(如 spring AMQP)。

所以我在 SuperPom 中组织了共享资源。

虽然 shade 插件似乎并没有真正干扰安装过程,但 antrun 插件当然找不到它应该复制的任何文件,因为 shade 插件没有创建任何 jar 文件。

因为我想在 SuperPom 中抽象出 shade/antrun 插件的配置,所以我需要跳过 shade/copy 目标。

我试过mvn clean install -Dmaven.shade.skip=true, mvn clean install -Dmaven.copy.skip=true, mvn clean install -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>

最佳答案

您是否尝试过在 super-pom 中将 maven-shade-plugin 的阶段设置为 none,然后在客户端 poms 中覆盖它?

所以在父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>

在需要它的子 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>

关于java - 如何跳过 maven antrun copy/shade :shade goal dynamically?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24969561/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com