Remove or delete resource files from target directory using pom file

I do agree with Matthew’s observations, but I got the impression that the original poster was asking how to automate execution of clean during (normal) “execution” of a profile.

You can define a plugin execution for the Maven Clean Plugin. It is normally only bound to clean, but by defining a plugin execution you can bind clean:clean (that is the clean goal of the clean plugin) to whichever lifecycle phase you want. The documentation of the Maven Clean Plugin has an example of how to do this. The documentation also has an example of deleting additional files. Merged the two looks like this:

  <plugin>
    <artifactId>maven-clean-plugin</artifactId>
    <version>2.5</version>
    <executions>
      <execution>
        <id>auto-clean</id>
        <phase>initialize</phase>
        <goals>
          <goal>clean</goal>
        </goals>
        <configuration>
         <filesets>
            <fileset>
              <directory>some/relative/path</directory>
            </fileset>
          </filesets>
        </configuration>
      </execution>
    </executions>
  </plugin>

Leave a Comment