25

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?

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
n002213f
  • 7,805
  • 13
  • 69
  • 105

3 Answers3

52

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>
JoseK
  • 31,141
  • 14
  • 104
  • 131
4

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

Andreas Dolk
  • 113,398
  • 19
  • 180
  • 268
0

Please read up on the maven lifecycle especially the package lifecycle.

The maven clean plugin you use will probably allow you to define a clean goal at a particular pahse. You can also execute for example mvn clean install -P profile

nkr1pt
  • 4,691
  • 5
  • 35
  • 55
  • 2
    i'm currently manually specifying the clean goal on the command line, since we can deploy to PROD from maven, forgetting `clean` might cause indeterminate behavior. – n002213f Sep 02 '10 at 07:08