在 Maven 原型集成测试中覆盖 属性

Overriding property in maven archetype integration test

我正在从原型生成一个项目,我在这个生成的项目 (archetype-resources/pom) 的 pom 中有一个 属性:

  <properties>
    <myProperty>productionValue</myProperty>
  </properties>

以及以下万无一失的配置:

      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.22.2</version>
        <configuration>
          <argLine>
            -Djava.library.path=${myProperty}
          </argLine>
        </configuration>
      </plugin>

我希望 myProperty 在我 运行 IT 时被我的原型 pom 的值覆盖,并在用户生成此项目时保持不变。我该怎么做?

我尝试在 archetype.properties 文件中设置它,但它有一个变量: myProperty=${project.basedir}/IT/path。 我希望 ${project.basedir} 在 IT 的情况下成为原型项目的基础,而不是生成项目的基础,当我这样做时情况并非如此。

我尝试的另一种方法是使用插件配置:

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-archetype-plugin</artifactId>
          <version>${maven-archetype.version}</version>
          <executions>
            <execution>
                <goals>
                    <goal>integration-test</goal>
                </goals>
              <configuration>
                <properties>
                  <myProperty>${project.basedir}/IT/path</myProperty>
                </properties>
              </configuration>
            </execution>
          </executions>
        </plugin>

但效果不佳,生成项目的pom中的myProperty没有改变。我做错了什么?非常感谢您的帮助!

问题是我把

<configuration>
  <properties>
    <myProperty>${project.basedir}/IT/path</myProperty>
  </properties>
</configuration>

<execution> 标签下,而不是 <plugin>。在我这样做之后,它按预期工作了。