Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force Maven clean

Tags:

I have a project with 2 profiles, because UAT and PROD use different versions of the same jar.

I have noticed that if i don't explicitly call mvn clean ... the deployed EAR will have BOTH UAT and PROD jars.

Is there a way in the POM to specify that Maven should always clean before any building?

like image 763
n002213f Avatar asked Sep 02 '10 06:09

n002213f


People also ask

What is Maven clean command?

mvn clean: Cleans the project and removes all files generated by the previous build. mvn compile: Compiles source code of the project. mvn test-compile: Compiles the test source code.

How do I run Maven clean?

Cleaning a Maven project using the command-line The Clean Plugin can be called to execute in the command-line without any additional configurations. Like the other plugins, to run the Clean Plugin, you use: mvn clean:clean.

How do I force Maven to reinstall dependencies?

In Maven, you can use Apache Maven Dependency Plugin, goal dependency:purge-local-repository to remove the project dependencies from the local repository, and re-download it again.


2 Answers

Use the maven-clean-plugin with the initialize phase as given here

http://maven.apache.org/plugins/maven-clean-plugin/usage.html

<project>   [...]   <build>     <plugins>       <plugin>         <artifactId>maven-clean-plugin</artifactId>         <version>2.4.1</version>         <executions>           <execution>             <id>auto-clean</id>             <phase>initialize</phase>             <goals>               <goal>clean</goal>             </goals>           </execution>         </executions>       </plugin>     </plugins>   </build>   [...] </project> 
like image 66
JoseK Avatar answered Oct 16 '22 13:10

JoseK


Sure. Visit the Maven clean plugin usage page, they provide an example how to run the plugin automatically during build.

like image 20
Andreas Dolk Avatar answered Oct 16 '22 13:10

Andreas Dolk