views:

489

answers:

2

How to remove generated build artefacts from Maven's target directory? Maven generates a jar or war file to target directory. I'd like to remove that file after maven has installed the jar/war file to local repository (that is, after maven has executed the 'install' goal). The remove could happen either at install goal or separate goal I execute manually.

Note, that I'd like leave other parts of target directory intact, for example target/site and target/surefire-reports.

A: 

There is nothing built into Maven that can do this. You could use the antrun plugin to execute an Ant script after install that deletes the artifact, or use the exec plugin to use the command line to delete the artifact, or write your own plug-in.

I suggest there is little value, if any, in doing any of these things. Maven is designed to place intermediate and final artifacts in target to make follow-on builds more efficient. The reason that there is nothing available to do this already is an indicator that this is of little value. If it is of value to you, you have a few options.

SingleShot
Well, that's just not true. See domi's answer. Having that said, I still wonder why would one do this.
Pascal Thivent
+5  A: 

Just use the clean plugin and run an execution after the install phase:

  <plugin>
    <artifactId>maven-clean-plugin</artifactId>
    <version>2.2</version>
    <executions>
      <execution>
        <id>auto-clean</id>
        <phase>install</phase>
        <goals>
          <goal>clean</goal>
        </goals>
        <configuration>
          <filesets>
            <fileset>
              <directory>${project.build.outputDirectory}</directory>
              <includes>
                <include>**/*.jar</include>
              </includes>
            <fileset>
           <filesets>
         </configuration>
      </execution>
    </executions>
  </plugin>
domi
+1 for the filter, but the directory element should be ${project.build.outputDirectory} to allow for overridden values
Rich Seller