maven pom - 定义一个配置文件来自定义插件配置

时间:2016-11-21 14:16:07

标签: maven plugins profile

我在pom中有以下插件:

  <plugin>
    <groupId>com.github.klieber</groupId>
    <artifactId>phantomjs-maven-plugin</artifactId>
    <configuration>
      <version>${phantomjs.version}</version>
      <checkSystemPath>false</checkSystemPath>          
      <skip>${skipTests}</skip>
    </configuration> 
    <executions>
      <execution>
        <goals>
          <goal>install</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

我想定义一个新的配置文件来自定义插件配置:

<profile>
  <id>enduserTest</id>

  <properties>
    <tomcat.version>8.0.39</tomcat.version>              
    <skipTests>true</skipTests>
  </properties>      

  <build>
    <defaultGoal>clean verify cargo:run</defaultGoal>
    <plugins>          

  <plugin>
    <groupId>com.github.klieber</groupId>
    <artifactId>phantomjs-maven-plugin</artifactId>
    <configuration>
      <version>${phantomjs.version}</version>
      <checkSystemPath>false</checkSystemPath>          
    </configuration> 
    <executions>
      <execution>
        <goals>
          <goal>install</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

唯一的区别是<skip>${skipTests}</skip> 线。 现在我想运行mvn -PenduserTest,但配置不会被覆盖。 有什么建议?有没有更好的解决方案呢?这是正确的策略吗?

1 个答案:

答案 0 :(得分:0)

如果所需的行为是在运行配置文件时跳过测试,那么您的逻辑没有错。验证我测试此代码,这是按预期工作(它跳过-PenduserTest测试):

<dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.2</version>
        </dependency>
    </dependencies>

    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
             <plugin>
            <groupId>com.github.klieber</groupId>
            <artifactId>phantomjs-maven-plugin</artifactId>
            <version>0.7</version>
            <configuration>
              <version>2.1.1</version>
              <checkSystemPath>false</checkSystemPath>          
              <skip>${skipTests}</skip>
            </configuration> 
            <executions>
              <execution>
                <goals>
                  <goal>install</goal>
                </goals>
              </execution>
            </executions>
          </plugin>


            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source />
                    <target />
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
      <id>enduserTest</id>

      <properties>
        <tomcat.version>8.0.39</tomcat.version>              
        <skipTests>true</skipTests>
      </properties>      

      <build>
        <defaultGoal>clean verify cargo:run</defaultGoal>
        <plugins>          

      <plugin>
        <groupId>com.github.klieber</groupId>
        <artifactId>phantomjs-maven-plugin</artifactId>
        <version>0.7</version>
        <configuration>
          <version>0.7</version>
          <checkSystemPath>false</checkSystemPath>          
        </configuration> 
        <executions>
          <execution>
            <goals>
              <goal>install</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      </plugins>
      </build>
      </profile>
    </profiles>

</project>