gpt4 book ai didi

Maven project.build.testSourceDirectory 属性在配置文件中不起作用

转载 作者:行者123 更新时间:2023-12-03 16:45:10 25 4
gpt4 key购买 nike

我想对maven项目中的不同文件夹进行测试,我需要更改maven的project.build.testSourceDirectory属性(property)。

我正在使用 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>
<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>

正在执行 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] 执行任务
[回声] ** 显示属性值 **
[echo]/home/username/workspace/projectName/core/src/test/java
[回声] 真

并与 <maven.test.skip>false</maven.test.skip>maven-antrun-plugin这给了我:

[INFO] 执行任务
[回声] ** 显示属性值 **
[echo]/home/username/workspace/projectName/core/src/test/java
[回声] 假

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

我知道配置文件被激活是因为我使用了 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>

    那里的属性已更改(但我需要为该属性分配多个值)。
    我试过 maven-surefire-plugin并且也不起作用。

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

    最佳答案

    我发现这个问题的解决方案不是很好,但它是一个解决方案。对我来说它正在工作并且它改变了 testSourceDirectory多变的。

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

    <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>

    开头 build标签我设置了 testSourceDirectory
    <project ...>
    <build>
    <testSourceDirectory>${myTestSourceDirectory}</testSourceDirectory>
    ...
    <build>
    ...
    </project>

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

    关于Maven project.build.testSourceDirectory 属性在配置文件中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19139509/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com