0

In my project, module C has parent B which has parent A.

parent A pom

<pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-clean-plugin</artifactId>
            <version>3.0.0</version>
        </plugin>
    </plugins>
</pluginManagement>

parent B pom

<pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-clean-plugin</artifactId>
            <executions>
                <execution>
                    <id>clean-extra-files</id>
                    <goals>
                        <goal>clean</goal>
                    </goals>
                    <configuration>
                        <filesets>
                            <fileset>
                                <directory>C:\foo\bar</directory>
                                <includes>
                                    <include>foo*.jar</include>
                                </includes>
                                <followSymlinks>false</followSymlinks>
                            </fileset>
                        </filesets>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</pluginManagement>

module C pom

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-clean-plugin</artifactId>
    <executions>
        <execution>
            <id>clean-extra-files</id>
            <phase>pre-integration-test</phase>
        </execution>
    </executions>
</plugin>

When I run mvn clean pre-integration-test

[INFO] --- maven-clean-plugin:3.0.0:clean (clean-extra-files) @ foo-c ---
[INFO] Deleting C:\dev\workspace\foo-a\foo-b\foo-c\target
[INFO] Deleting C:\foo\bar (includes = [foo*.jar], excludes = [])

Both the default target directory and my additional directory are cleaned. However, I only want the additional directory cleaned.

How do I prevent clean-extra-files from cleaning the default target directory?

If it is not possible, what other options are there for cleaning up unwanted files?

Env: Java:6, Eclipse:Luna, Maven:3.2

Zack
  • 3,819
  • 3
  • 27
  • 48

2 Answers2

0

I believe there is an "excludes" tag which you can use.

    <fileset>
      <directory>some/relative/path</directory>
      <includes>
        <include>**/*.tmp</include>
        <include>**/*.log</include>
      </includes>
      <excludes>
        <exclude>**/important.log</exclude>
        <exclude>**/another-important.log</exclude>
      </excludes>
      <followSymlinks>false</followSymlinks>
    </fileset>

http://maven.apache.org/plugins/maven-clean-plugin/examples/delete_additional_files.html

http://maven.40175.n5.nabble.com/How-to-delete-a-directory-td123552.html

Rajind Ruparathna
  • 2,215
  • 24
  • 55
  • This only excludes on the directory I defined in the fileset. The default clean on the target directory still fires. – Zack Oct 05 '16 at 15:20
0

It doesn't seem to be a way to do it with the maven-clean-plugin, so I used an antrun task inspired by this post:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
            <id>delete-install-files</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <tasks>
                    <delete>
                        <fileset dir="C:\foo\bar"
                            includes="foo*.jar" />
                    </delete>
                </tasks>
            </configuration>
        </execution>
    </executions>
</plugin>
Community
  • 1
  • 1
Zack
  • 3,819
  • 3
  • 27
  • 48