tags:

views:

34

answers:

2

hi,

i know this is probably frowned upon by maven lovers, but the whole 'target' directory is a waste of space in the context of our program and it's deployment. we have other build processes responsible for creating the actual deployment and i currently manually delete the target dir after every maven build, so that its contents don't interfere with my file searches etc...

is there a way to delete this dir automatically at the end of a maven build/install?

thanks, p.

+5  A: 

Use the maven-clean-plugin as here http://maven.apache.org/plugins/maven-clean-plugin/examples/delete_additional_files.html

<project>


[...]
  <build>
<plugins>
  <plugin>
    <artifactId>maven-clean-plugin</artifactId>
    <version>2.4.1</version>
    <executions>
      <execution>
        <id>auto-clean</id>
        <phase>install</phase>
        <goals>
          <goal>clean</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
</plugins>
  </build>
  [...]
</project>
JoseK
This will run the cleaning at the beginning of the build and not at the end.
khmarbaise
@khmarbaise - i've changed the phase to install and it works even at the end. But i am calling mvn install. For a mvn package to work, i need to use the phase for maven-clean-plugin as package,and it does it at the end.
JoseK
Just be careful you don't delete before deploy or install phase, the project will become useless.
sal
+1  A: 

You should simply add the clean goal to your maven goals at the end.

mvn install clean

The problem with the clean-plugin is that if you like to run the clean at the end of the build it depends which goal you called at the beginning. For example you called mvn package you need to have a phase post-package which does not exist or if you called mvn install you have to have phase post-install which does not exist either.

khmarbaise
@khmarbaise - clean-plugin works with the phase install/package even at the end. you dont need post-install/post-package. but it does need to match the original phase called.
JoseK