Thursday, October 17, 2013

Exclude files from War packaging by Maven profile

To achieve this I have used the "packagingExcludes" property of Maven war plugin. For more info and examples of using this property see this page. To exclude files by Maven profile you need to first parameterize the value of "packagingExcludes" in war plugin declaration in pom file

     <plugin>  
          <artifactId>maven-war-plugin</artifactId>  
          <version>2.1.1</version>                      
          <configuration>  
                <packagingExcludes>${pkg.exclude}</packagingExcludes>                                     
          </configuration>  
     </plugin>  

In Maven profile you can define the value of this property by profile

            <profile>  
                  <id>prod</id>  
                  <properties>  
                       <pkg.exclude>WEB-INF/classes/com/internal/*.class,internal/*</pkg.exclude>                                                                                       
                  </properties>  
                  <activation>  
                       <property>  
                         <name>environment</name>  
                         <value>prod</value>  
                       </property>  
                  </activation>                      
            </profile>