gpt4 book ai didi

Maven:如何指定运行哪个程序集插件执行

转载 作者:行者123 更新时间:2023-12-03 21:06:39 25 4
gpt4 key购买 nike

我有一个有多个程序集执行的 pom。当我运行时,例如mvn package ,它运行所有的执行。我怎么能告诉它只运行 foo执行?

<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>foo/id>
<phase>package</phase>
<goals><goal>single</goal></goals>
<configuration>...</configuration>
</execution>
<execution>
<id>bar</id>
<phase>package</phase>
<goals><goal>single</goal></goals>
<configuration>...</configuration>
</execution>

我上面的,在我看来,类似于下面的 Makefile :
all: foo bar

foo:
... build foo ...

bar:
... build bar ...

我可以运行 make all或者干脆 make构建一切,或者我可以运行 make foomake bar建立个人目标。如何使用 Maven 实现这一目标?

最佳答案

您需要使用 profiles ,这里是 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mycompany</groupId>
<artifactId>FooBar</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<profiles>

<profile>
<id>Foo</id>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>foo/id>
<phase>package</phase>
<goals><goal>single</goal></goals>
<!-- configuration>...</configuration -->
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>Bar</id>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>Bar</id>
<phase>package</phase>
<goals><goal>single</goal></goals>
<!-- configuration>...</configuration -->
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

</profiles>

</project>

你会像这样调用 maven:
mvn package -P Foo  // Only Foo
mvn package -P Bar // Only Bar
mvn package -P Foo,Bar // All (Foo and Bar)

关于Maven:如何指定运行哪个程序集插件执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7086115/

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