Pages

21/09/2019

[Maven] Delete folders during specific phase

Using Maven clean plugin, it is possible to specify a clean behaviour to delete only selected folders during a certain phase:

 <build>  
   <plugin>  
     <artifactId>maven-clean-plugin</artifactId>  
     <version>3.1.0</version>  
     <executions>  
       <execution>  
         <id>YOUR_ID</id>  
         <phase>SOME_PHASE</phase>  
         <goals>  
           <goal>clean</goal>  
         </goals>  
         <configuration>  
           <excludeDefaultDirectories>true</excludeDefaultDirectories>  
             <filesets>  
               <fileset>  
                 <directory>some/directory</directory>  
               </fileset>  
             </filesets>  
         </configuration>  
       </execution>  
     </executions>  
   </plugin>  
 </build>  


Important parameters are:

  • excludeDefaultDirectories to avoid cleaning also the directories that a normal mvn:clean execution would
  • fileset to specify only the directories to delete

No comments:

Post a Comment

With great power comes great responsibility