Maven:如何指定运行哪个程序集插件执行
我有一个具有多个程序集执行的 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 foo
或 make bar
来构建单独的目标。我怎样才能用 Maven 实现这个目标?
I have a pom with multiple assembly executions. When I run, e.g. mvn package
, it runs all the executions. How can I tell it to only run the foo
execution?
<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>
What I have above is, in my mind, similar to the following Makefile
:
all: foo bar
foo:
... build foo ...
bar:
... build bar ...
I can run a make all
or simply make
to build everything, or I can run make foo
or make bar
to build individual targets. How can I achieve this with Maven?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要使用 profiles,这是一个
pom .xml
示例:您可以像这样调用 Maven:
You need to use profiles, here is a
pom.xml
example:And you would invoke maven like this:
我的 Maven 有点生疏,但我认为你可以通过几种方法来做到这一点:
1)使用配置文件。使用“maven -PprofileName”在命令行上指定配置文件。
2)将您的执行分为不同的阶段/目标,并仅运行您想要的阶段/目标。
My Maven is a bit rusty but I think you can do this a couple of ways:
1) Use profiles. Specify a profile on the command line with "maven -PprofileName".
2) Put your executions in separate phases/goals and run only the ones you want.
如果您不希望“bar”运行,则不要将其绑定到生命周期阶段。插件执行仅在绑定到某个阶段并且该阶段作为构建的一部分执行时运行。正如 TheCoolah 所建议的,配置文件是管理何时将执行绑定到生命周期阶段以及何时不绑定的一种方法。
If you don't want "bar" to run, then don't bind it to a lifecycle phase. Plugin executions only run when they are bound to a phase and that phase executes as part of a build. As TheCoolah suggested, profiles are one way of managing when executions are bound to lifecycle phases and when not.