2016-11-21 71 views
0

我在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,但配置不會被覆蓋。 有什麼建議嗎?有沒有更好的解決方案來做到這一點?這是正確的策略嗎?

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