【发布时间】:2013-10-08 23:45:04
【问题描述】:
我想对 maven 项目中的不同文件夹进行测试,我需要更改 maven 的 project.build.testSourceDirectory 属性。
我正在使用 maven 配置文件来解决这个问题。
我的个人资料如下所示:
<profiles>
<profile>
<id>sahi_UI_testing</id>
<activation>
<property>
<name>sahiTesting</name>
<value>true</value>
</property>
</activation>
<properties>
<maven.test.skip>false</maven.test.skip>
<project.build.testSourceDirectory>src/test/java/org/package1/package2/sahi</project.build.testSourceDirectory>
</properties>
</profile>
</profiles>
project.build.testSourceDirectory 没有改变,只保留默认的/home/username/workspace/projectName/core/src/test/java(我已经用maven-antrun-plugin 对此进行了测试并给出了该路径)。
我在项目中有多个 pom.xml,所以在路径中我有 ../core/.. 文件夹(这是项目的核心 pom.xml)。
maven-antrun-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>******** Displaying value of property ********</echo>
<echo>${project.build.testSourceDirectory}</echo>
<echo>${maven.test.skip}</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
在maven-antrun-plugin 中执行mvn help:active-profiles -f core/pom.xml -Dtest=JavaClientTest -o -e test -DsahiTesting=true 和<maven.test.skip>true</maven.test.skip> 这给了我:
[INFO] 执行任务
[echo] ** 显示属性值 **
[echo] /home/username/workspace/projectName/core/src/test/java
[回声] 真
和<maven.test.skip>false</maven.test.skip> 在maven-antrun-plugin 这给了我:
[INFO] 执行任务
[echo] ** 显示属性值 **
[echo] /home/username/workspace/projectName/core/src/test/java
[回声] 假
因此,我们可以看到另一个变量已更改。
我知道配置文件已激活,因为我使用了maven-help-plugin 来识别它。maven-help-plugin 给了我这个结果:
以下配置文件处于活动状态:
- sahi_UI_testing(来源:pom)
我尝试在没有 maven 配置文件的情况下仅更改 <build> 标记中的 project.build.testSourceDirectory 属性。
...
<build>
<testSourceDirectory>src/test/java/org/package/package2/sahi</testSourceDirectory>
...
</build>
该属性已更改(但我需要为该属性分配多个值)。
我试过maven-surefire-plugin 也没用。
问题是为什么project.build.testSourceDirectory在使用配置文件时没有改变?
【问题讨论】: