2015-07-22 54 views
2

我有一個帶有父POM的多模塊maven項目。項目的一個孩子根據個人資料爲不同的環境定製,父母也根據選定的環境(資料)建立所需的模塊。阻止構建未激活配置文件的maven模塊

因爲環境沒有「通用」或「默認」版本,所以我想阻止構建(讀作「在子模塊中運行mvn包」)自定義子項目而不激活配置文件。換句話說,我想強制開發人員使用環境依賴的配置文件。

有沒有可能這樣做?

+0

您可以使用[Maven Enforcer](https://maven.apache.org/enforcer/enforcer-rules/requireActiveProfile.html)。完美的使用案例。 –

回答

4

Maven Enforcer僅針對此要求。只需添加所需的配置文件。

<project> 
    [...] 
    <build> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-enforcer-plugin</artifactId> 
     <version>1.4</version> 
     <executions> 
      <execution> 
      <id>enforce-all-profiles-are-activated</id> 
      <goals> 
       <goal>enforce</goal> 
      </goals> 
      <configuration> 
       <rules> 
       <requireActiveProfile> 
        <profiles>first,second</profiles> 
       </requireActiveProfile> 
       </rules> 
       <fail>true</fail> 
      </configuration> 
      </execution> 
     </executions> 
     </plugin> 
    </plugins> 
    </build> 
    [...] 
</project> 
相關問題