2015-07-22 55 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> 
相关问题