Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

delete the 'target' directory after build

Tags:

maven

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.

like image 341
pstanton Avatar asked May 26 '10 09:05

pstanton


2 Answers

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>
like image 157
JoseK Avatar answered Oct 23 '22 04:10

JoseK


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.

like image 38
khmarbaise Avatar answered Oct 23 '22 04:10

khmarbaise