2011-12-08 40 views
1

我正在使用Maven 3.0.3。如果有人運行包含「驗證」階段的Maven任務,我想確保定義了一個屬性「tomcat.manager.url」,如果不是,則拋出一個錯誤。但是,如果有人沒有運行包含驗證的命令(例如mvn test),我不想拋出任何錯誤。Maven:我如何在生命週期階段強制執行財產包含?

我該怎麼做?

謝謝 - 戴夫

回答

3

您可以設置的實施者插件(docs)期間,需要該插件被設置規則中的「驗證」階段來執行,該配置將是這個樣子:

<build> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-enforcer-plugin</artifactId> 
     <version>1.0.1</version> 
     <executions> 
      <execution> 
      <id>enforce-property</id> 
      <goals> 
       <goal>enforce</goal> 
      </goals> 
      <phase>verify</phase> 
      <configuration> 
       <rules> 
       <requireProperty> 
        <property>tomcat.manager.url</property> 
        <message>You must set a tomcat manager url</message> 
       </requireProperty> 
       </rules> 
       <fail>true</fail> 
      </configuration> 
      </execution> 
     </executions> 
     </plugin> 
    </plugins> 
    </build> 

由於插件只會在驗證階段執行,因此除非您正在運行達到該階段的版本,否則不會執行檢查。

相關問題