如何从子pom覆盖Maven 3.0父配置文件属性?

时间:2013-08-17 19:49:57

标签: maven-3 jmeter jmeter-maven-plugin

如何从子pom中覆盖Maven 3.0父配置文件属性?

我希望从父pom覆盖配置文件属性。我已经使用过help:effective-pom -Pjmeter,可以看到子属性没有被拾取并尝试了许多不同的排列都没有成功。我希望子属性覆盖父属性。

父母pom资料:

<profile>
  <id>jmeter</id>
  <properties combine.self="override">
    <maven.jmeter.phase>verify</maven.jmeter.phase>
    <maven.jmeter.goal>jmeter</maven.jmeter.goal>
    <!-- We use the ${basedir} to avoid NullPointer errors when src/test/jmeter doesn't exist -->
    <!-- when running jmeter test the default to set in the child pom is  ${basedir}/src/test/jmeter  -->
    <maven.jmeter.testFilesDirectory>${basedir}</maven.jmeter.testFilesDirectory>
    <maven.jmeter.jMeterTestFile>**/*.jmx</maven.jmeter.jMeterTestFile>
    <maven.jmeter.excludeJmeterTestFile>NOT_NULL</maven.jmeter.excludeJmeterTestFile>
    <maven.jmeter.testResultsTimestamp>false</maven.jmeter.testResultsTimestamp>
    <maven.jmeter.server>localhost</maven.jmeter.server>
    <maven.jmeter.port>8080</maven.jmeter.port>
  </properties>
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>com.lazerycode.jmeter</groupId>
          <artifactId>jmeter-maven-plugin</artifactId>
          <version>${jmeter.version}</version>
          <executions>
            <execution>
              <id>jmeter-tests</id>
              <phase>${maven.jmeter.phase}</phase>
              <goals>
                <goal>${maven.jmeter.goal}</goal>
              </goals>
              <configuration>
                <testFilesDirectory>${maven.jmeter.testFilesDirectory}</testFilesDirectory>
                <testFilesIncluded>
                  <jMeterTestFile>${maven.jmeter.jMeterTestFile}</jMeterTestFile>
                </testFilesIncluded>
                <testFilesExcluded>
                  <excludeJmeterTestFile>${maven.jmeter.excludeJmeterTestFile}</excludeJmeterTestFile>
                </testFilesExcluded>
                <testResultsTimestamp>${maven.jmeter.testResultsTimestamp}</testResultsTimestamp>
                <propertiesUser>
                  <!-- server and port must be defined (and used) in the JMeter jmx file as User Defined Variables
                        ${__P(server,localhost)}
                        ${__P(port,80)}
                       See http://jmeter.apache.org/usermanual/component_reference.html#User_Defined_Variables
                           http://jmeter.apache.org/usermanual/test_plan.html#using_variables
                           http://jmeter.apache.org/usermanual/functions.html#__P
                           http://jmeter.apache.org/usermanual/best-practices.html#parameterising_tests
                  -->
                  <server>${maven.jmeter.server}</server>
                  <port>${maven.jmeter.port}</port>
                </propertiesUser>
              </configuration>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</profile>

然后在孩子pom:

<profile>
  <id>jmeter</id>
  <activation><activeByDefault>false</activeByDefault></activation>
  <properties>
    <maven.jmeter.testFilesDirectory>${project.basedir}/src/test/jmeter</maven.jmeter.testFilesDirectory>
    <!-- csv based JMeter tests result in one graph in Jenkins, we want a graph per test -->
    <maven.jmeter.excludeJmeterTestFile>**/KRAD.jmx</maven.jmeter.excludeJmeterTestFile>
  </properties>
</profile>

1 个答案:

答案 0 :(得分:3)

我不确定属性是否会被覆盖。无论哪种方式,插件都不会像你一样运行,因为你只在<pluginManagement>下定义了<plugins>而没有直接<build>个孩子。如果您不希望您的插件在父级中运行,只需在孩子中定义<plugins>标签,并确保其运行:

<profile>
  <id>jmeter</id>
  <activation><activeByDefault>false</activeByDefault></activation>
  <build>
    <plugins>
      <plugin>
        <groupId>com.lazerycode.jmeter</groupId>
        <artifactId>jmeter-maven-plugin</artifactId>
        <configuration>
          <testFilesDirectory>${maven.jmeter.jMeterTestFile}</testFilesDirectory>
          <!-- csv based JMeter tests result in one graph in Jenkins, we want a graph per test -->
          <testFilesExcluded>
            <excludeJmeterTestFile>${maven.jmeter.excludeJmeterTestFile}</excludeJmeterTestFile>
          </testFilesExcluded>
        </configuration>
      </plugin>
    </plugins>
  </build>
</profile>

希望这有帮助。