Dav*_*ips 14 maven-3 maven maven-assembly-plugin
我有一个有多个程序集执行的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>
Run Code Online (Sandbox Code Playgroud)
在我看来,我的上述内容类似于以下内容Makefile:
all: foo bar
foo:
... build foo ...
bar:
... build bar ...
Run Code Online (Sandbox Code Playgroud)
我可以运行make all或只是make构建一切,或者我可以运行make foo或make bar构建单个目标.我怎样才能用Maven实现这个目标?
Jér*_*nge 30
您需要使用配置文件,这是一个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>
Run Code Online (Sandbox Code Playgroud)
你会像这样调用maven:
mvn package -P Foo // Only Foo
mvn package -P Bar // Only Bar
mvn package -P Foo,Bar // All (Foo and Bar)
Run Code Online (Sandbox Code Playgroud)
我的Maven有点生疏,但我认为你可以通过以下两种方式做到这一点:
1)使用配置文件.使用"maven -PprofileName"在命令行上指定配置文件.
2)将你的执行放在不同的阶段/目标中,只运行你想要的那些.
| 归档时间: |
|
| 查看次数: |
9491 次 |
| 最近记录: |