Maven 2.x Clean Plugin

Cannot Supress Default clean while still cleaning

Details

  • Type: New Feature New Feature
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 2.1.1
  • Fix Version/s: 2.3
  • Component/s: None
  • Labels:
    None
  • Number of attachments :
    0

Description

We would like to configure clean in our parent pom to remove the log files in logs in all our child modules. We've done that like this:

<plugin>
    <artifactId>maven-clean-plugin</artifactId>
    <version>2.1.1</version>
    <configuration>
        <filesets>
            <fileset>
                <directory>${basedir}/logs</directory>
                <followSymlinks>false</followSymlinks>
                <excludes>
                    <exclude>**/.svn</exclude>
                </excludes>
            </fileset>
        </filesets>
    </configuration>
</plugin>

The problem is that when we want to clean an extra directory out of a module, say for example, generated-sources:

<plugin>
    <artifactId>maven-clean-plugin</artifactId>
    <version>2.1.1</version>
    <executions>
        <execution>
            <id>gensrc</id>
            <phase>clean</phase>
            <goals>
                <goal>clean</goal>
            </goals>
            <configuration>
                <filesets>
                    <fileset>
                        <directory>generated-sources</directory>
                        <followSymlinks>false</followSymlinks>
                    </fileset>
                </filesets>
            </configuration>
        </execution>
    </executions>
</plugin>

We then see the following when we run "mvn clean":

[INFO] Building Generated Sources
[INFO]    task-segment: [clean]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory /Users/jpollak/src/software/projects/mhs/trunk/mhs-gensrc/target
[INFO] Deleting directory /Users/jpollak/src/software/projects/mhs/trunk/mhs-gensrc/target/classes
[INFO] Deleting directory /Users/jpollak/src/software/projects/mhs/trunk/mhs-gensrc/target/test-classes
[INFO] Deleting directory /Users/jpollak/src/software/projects/mhs/trunk/mhs-gensrc/target/site
[INFO] Deleting file-set: /Users/jpollak/src/software/projects/mhs/trunk/mhs-gensrc/logs (included: [], excluded: [**/.svn])
[INFO] [clean:clean {execution: gensrc}]
[INFO] Deleting directory /Users/jpollak/src/software/projects/mhs/trunk/mhs-gensrc/target
[INFO] Deleting directory /Users/jpollak/src/software/projects/mhs/trunk/mhs-gensrc/target/classes
[INFO] Deleting directory /Users/jpollak/src/software/projects/mhs/trunk/mhs-gensrc/target/test-classes
[INFO] Deleting directory /Users/jpollak/src/software/projects/mhs/trunk/mhs-gensrc/target/site
[INFO] Deleting file-set: generated-sources (included: [], excluded: [**/.svn])
[INFO] ------------------------------------------------------------------------

It would be nice to suppress cleaning target a second time.

Activity

Hide
Barrie Treloar added a comment -

A workaround is to use the antrun plugin.

Something like this (I have not tested this properly)

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>gensrc</id>
            <phase>clean</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <tasks>
                <delete>
                  <fileset dir="generated-sources" includes="**/*" />
                </delete>
              </tasks>
            </configuration>
          </execution>
        </executions>
      </plugin>
Show
Barrie Treloar added a comment - A workaround is to use the antrun plugin. Something like this (I have not tested this properly)
<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>gensrc</id>
            <phase>clean</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <tasks>
                <delete>
                  <fileset dir="generated-sources" includes="**/*" />
                </delete>
              </tasks>
            </configuration>
          </execution>
        </executions>
      </plugin>
Hide
Benjamin Bentmann added a comment -

Added new parameter excludeDefaultDirectories in r692713.

Show
Benjamin Bentmann added a comment - Added new parameter excludeDefaultDirectories in r692713.

People

Vote (1)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: