Maven project.build.testSourceDirectory属性无法从配置文件工作
我想对maven项目中的不同文件夹进行测试,需要更改maven的Maven project.build.testSourceDirectory属性无法从配置文件工作,maven,pom.xml,Maven,Pom.xml,我想对maven项目中的不同文件夹进行测试,需要更改maven的project.build.testSourceDirectory属性 我正在使用maven配置文件解决这个问题 我的个人资料如下所示: <profiles> <profile> <id>sahi_UI_testing</id> <activation> <property>
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>
使用
true
在maven-antrun插件中执行mvn帮助:活动概要文件-f core/pom.xml-Dtest=JavaClientTest-o-e test-DsahiTesting=true
这给了我:
[信息]执行任务
[echo]***显示属性值***
[echo]/home/username/workspace/projectName/core/src/test/java
[回声]正确
使用maven-antrun-plugin
中的false
,我会:
[信息]执行任务
[echo]***显示属性值***
[echo]/home/username/workspace/projectName/core/src/test/java
[回声]假
因此,我们可以看到另一个变量发生了变化。
我知道该配置文件被激活是因为我使用了maven帮助插件
来识别它。
maven帮助插件
给出了以下结果:
以下配置文件处于活动状态:
- sahi_测试(来源:pom)
我尝试在没有maven配置文件的情况下仅在
标记中更改项目.build.testSourceDirectory
属性。
。。。
src/test/java/org/package/package2/sahi
...
在那里,属性已更改(但我需要为该属性指定多个值)。
我尝试了maven-surefire插件
,但不起作用
问题是为什么在使用概要文件时,project.build.testSourceDirectory
没有更改?您不能用属性覆盖项目
模型,Maven不允许这样做。您唯一的选择是在您想要使用的插件中指定testSourceDirectory(假设它可用)。我发现这个问题的解决方案不是很好,但它是一个解决方案。对我来说,它正在工作,它更改了testSourceDirectory
变量
在pom.xml
文件中,我在properties
标记中声明了一个自己的变量,该标记使用testSourceDirectory
的默认值初始化:
<project ...>
...
<properties>
<myTestSourceDirectory>${project.basedir}/src/test/java</myTestSourceDirectory>
...
</properties>
...
</project>
因此,当我们不使用概要文件时,myTestSourceDirectory
变量有一个默认值,当我们使用概要文件时,变量将更改为请求的测试目录。变量始终存在,在build
标记中,我们将testSourceDirectory
属性更改为所需的值。现在我明白了,我不能在属性中覆盖项目
模型。我尝试过那个插件(maven-surefire-plugin
),但它不起作用。我在互联网上看到,插件的testSourceDirectory
对其他开发人员也不起作用。
...
<build>
<testSourceDirectory>src/test/java/org/package/package2/sahi</testSourceDirectory>
...
</build>
<project ...>
...
<properties>
<myTestSourceDirectory>${project.basedir}/src/test/java</myTestSourceDirectory>
...
</properties>
...
</project>
<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>
<myTestSourceDirectory>src/test/java/org/<package1>/<package2>/sahi</myTestSourceDirectory>
</properties>
</profile>
</profiles>
<project ...>
<build>
<testSourceDirectory>${myTestSourceDirectory}</testSourceDirectory>
...
<build>
...
</project>