使用Maven配置文件控制构建执行 [英] Using maven profiles to control build execution
问题描述
我需要修改大型项目的Maven构建,以在典型的开发构建过程中跳过某些步骤(即,不要构建* -source.jar文件).我已经搜索了maven的条件执行",但是什么也没找到.
I need to modify the maven build for a large project to skip certain steps during typical development builds (i.e. don't build the *-source.jar files). I've searched for "conditional execution" for maven, but haven't found anything.
开发者个人资料听起来像是执行此操作的直观方法-但我不知道Maven有多直观.配置文件的文档显示了如何为不同的配置文件设置不同的属性(即数据库连接参数).我想我可以设置一个属性,然后测试该属性是否在maven-source-plugin -executes-execution标记中设置.
A dev profile sounds like the intuitive way to do this - but I don't know how intuitive maven is. The docs for profiles show how to set different properties (i.e. database connection parameters) for different profiles. I suppose I could set a property and then test if that property is set in the maven-source-plugin - executions - execution tag.
这是在Maven中执行条件执行的正确方法吗?
Is this the right way to do conditional execution in maven?
在Maven中执行此操作的正确"方法是什么?
What's the "right" way to do this in maven?
推荐答案
您正在考虑的有点落后:让配置文件启用行为,而不是禁用它.这正是概要文件最擅长的,并且正是您的情况:您只希望在某些情况下运行这些步骤.因此,您可能会遇到类似这样的情况:
You're thinking about it a bit backwards: have the profile enable the behaviour, not disable it. This is just what profiles are best at, and is exactly your case: you only want the steps to be run in certain circumstances. So you might have something like:
<profile>
<id>source-jars</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
...
事实上,在 maven-source-plugin用法页面上有一个例子, /a>.当需要生成工件时,请使用mvn -P source-jars(或其他任何工具).而已!如果您只需要在发布时执行此操作,请发布插件甚至提供了一种定义配置文件以在发行插件配置中正确使用的方法.
And in fact there's an example just like this on the maven-source-plugin usage page. When you need to generates your artifact, use mvn -P source-jars (or whatever). That's it! If you only need to do this at release time, the release plugin even offers a way to define the profiles to use right in the release plugin configuration.
这篇关于使用Maven配置文件控制构建执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!