Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove generated build artifacts from Maven's target directory?

How to remove generated build artifacts 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.

like image 412
Juha Syrjälä Avatar asked Oct 12 '09 06:10

Juha Syrjälä


People also ask

How do I clear my target folder?

To delete the target directory, run mvn clean on your project directly from the command line. That will delete the target directory as expected. In contrast, running Run As > Maven clean from Eclipse for some reason leaves the target directory and subdirectories classes and test-classes.

How do I delete the artifact folder in local repository?

If you want to explicitly remove a single artifact from the cache, use purge-local-repository with the manualInclude parameter. For example, from the command line: mvn dependency:purge-local-repository -DmanualInclude="groupId:artifactId, ..."

What is the plugin name used to clean the target folder?

The Maven Clean Plugin will delete the target directory by default. You may configure it to delete additional directories and files.

What is Maven clean do?

The Maven Clean Plugin, as the name implies, attempts to clean the files and directories generated by Maven during its build. While there are plugins that generate additional files, the Clean Plugin assumes that these files are generated inside the target directory.


1 Answers

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>
like image 99
domi Avatar answered Oct 05 '22 11:10

domi