【问题标题】:Running maven-clean-plugin during pre-integration-test without cleaning default target directory在预集成测试期间运行 maven-clean-plugin 而不清理默认目标目录
【发布时间】:2017-02-12 20:58:34
【问题描述】:

在我的项目中,模块 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

【问题讨论】:

    标签: java eclipse apache maven maven-3


    【解决方案1】:

    我相信您可以使用一个“排除”标签。

        <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

    【讨论】:

    • 这仅排除我在文件集中定义的目录。目标目录上的默认清理仍然会触发。
    【解决方案2】:

    这似乎不是使用 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-24
      • 2019-05-08
      • 2018-05-28
      • 2018-07-30
      • 2010-10-28
      • 1970-01-01
      • 2017-10-19
      • 1970-01-01
      相关资源
      最近更新 更多