Maven:如何从命令行激活配置文件? [英] Maven: How do I activate a profile from command line?
问题描述
这是我pom.xml中的片段. 我尝试了以下操作,但是未激活配置文件.
This is a snippet from my pom.xml. I tried the following, but the profile was not activated.
mvn clean install -Pdev1
mvn clean install -P dev1
当我尝试mvn help:active-profiles
时,没有任何配置文件被列为活动状态.
如果我将dev1
的<activeByDefault>
设置为true
,然后运行mvn help:active-profiles
,则显示配置文件已激活.
When I tried mvn help:active-profiles
no profiles were listed as active.
If I set <activeByDefault>
for dev1
to true
, and run mvn help:active-profiles
, it shows me the profile is activated.
<profile>
<id>dev1</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<env>local</env>
<properties.file>src/test/resources/dev1.properties</properties.file>
</systemPropertyVariables>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/dev1.testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>dev2</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<env>local</env>
<properties.file>src/test/resources/dev2.properties</properties.file>
</systemPropertyVariables>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/dev2.testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
我想知道为什么我的个人资料没有被激活.有人遇到过类似的问题吗?
I am wondering why my profile is not getting activated. Has anyone encountered similar issue?
推荐答案
两个命令都是正确的:
mvn clean install -Pdev1
mvn clean install -P dev1
问题很可能不是配置文件激活,而是配置文件未达到您的预期.
The problem is most likely not profile activation, but the profile not accomplishing what you expect it to.
命令正常:
mvn help:active-profiles
不显示配置文件,因为它不包含-Pdev1
.您可以添加它以使配置文件显示,但这将毫无意义,因为您将测试Maven本身.
does not display the profile, because is does not contain -Pdev1
. You could add it to make the profile appear, but it would be pointless because you would be testing maven itself.
您应该执行的操作是检查个人资料的行为:
-
在配置文件配置中
- 将
activeByDefault
设置为true
, - 运行
mvn help:active-profiles
(以确保它有效 即使没有-Pdev1
也已激活), - 运行
mvn install
.
- set
activeByDefault
totrue
in the profile configuration, - run
mvn help:active-profiles
(to make sure it is effectively activated even without-Pdev1
), - run
mvn install
.
它应该提供与以前相同的结果,因此请确认问题出在配置文件未达到您的期望.
It should give the same results as before, and therefore confirm that the problem is the profile not doing what you expect.
这篇关于Maven:如何从命令行激活配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!