在预集成测试期间运行maven-clean-plugin而不清除默认目标目录

时间:2016-10-04 15:45:56

标签: java eclipse apache maven maven-3

在我的项目中,模块C有父B,父母A。

父母A pom

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

父母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>

模块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>

当我运行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 = [])

清除默认目标目录和我的附加目录。但是,我只希望清理其他目录。

如何阻止clean-extra-files清除默认目标目录?

如果不可能,还有哪些其他选项可用于清理不需要的文件?

环境:Java:6,Eclipse:Luna,Maven:3.2

2 个答案:

答案 0 :(得分:0)

我相信你可以使用“排除”标签。

    <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

答案 1 :(得分:0)

使用maven-clean-plugin似乎不是一种方法,所以我使用了受this post启发的antrun任务:

<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>