Maven project.build.testSourceDirectory属性不适用于配置文件

Nag*_*ila 3 pom.xml maven

我想在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>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)


执行mvn help:active-profiles -f core/pom.xml -Dtest=JavaClientTest -o -e test -DsahiTesting=true<maven.test.skip>true</maven.test.skip>maven-antrun-plugin这给了我:
[INFO]执行任务
[回音] **显示的属性值**
[回音] /首页/用户名/工作区/项目名称/核心/ src目录/ test/java下
[回音]真实

,并与<maven.test.skip>false</maven.test.skip>maven-antrun-plugin此给我:
[INFO]执行任务
[echo] **显示属性值**
[echo]/home/username/workspace/projectName/core/src/test/java
[echo] false

所以,我们可以看到另一个变量被改变了.

我知道配置文件已激活,因为我曾经maven-help-plugin认识到这一点.
maven-help-plugin给了我这样的结果:
下面的配置文件是活动:

  • sahi_UI_testing(来源:pom)

我试过没有maven的配置文件project.build.testSourceDirectory只在<build>标签中更改属性.

...
<build>
    <testSourceDirectory>src/test/java/org/package/package2/sahi</testSourceDirectory>
    ...
</build>
Run Code Online (Sandbox Code Playgroud)

该属性已更改(但我需要为该属性分配多个值).我试过了maven-surefire-plugin,也没用.

问题是project.build.testSourceDirectory使用配置文件时为什么没有改变?

Nag*_*ila 5

我找到了一个不太好的解决方案,但这是一个解决方案.对我而言,它正在发挥作用,它会改变testSourceDirectory变量.

pom.xml文件中,我在properties使用testSourceDirectory默认值初始化的标签中声明了一个自己的变量:

<project ...>
    ...
    <properties>
        <myTestSourceDirectory>${project.basedir}/src/test/java</myTestSourceDirectory>
        ...
    </properties>
    ...
</project>
Run Code Online (Sandbox Code Playgroud)

我的个人资料是:

<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>
Run Code Online (Sandbox Code Playgroud)

在开始build的标签,我设置testSourceDirectory

<project ...>
    <build>
        <testSourceDirectory>${myTestSourceDirectory}</testSourceDirectory>
        ...
    <build>
    ...
</project>
Run Code Online (Sandbox Code Playgroud)

因此,当我们不使用配置文件myTestSourceDirectory时,我们对变量有一个默认值,当我们使用配置文件时,变量将被更改为请求的测试目录.变量始终存在,并且在build标记中我们将testSourceDirectory属性更改为所需的值.