在maven generate-sources或maven安装期间删除文件夹

时间:2018-08-06 13:05:04

标签: java xml maven pom.xml maven-plugin

我正在尝试删除文件夹,然后再执行generate-sourcesinstall。我已经在clean的{​​{1}}下的文件夹中执行此操作,但是我想在其他时间尝试一下,只是因为我确定无法忘记删除某些文件/夹。怎么办?

1 个答案:

答案 0 :(得分:2)

请参见Apache Maven Clean Plugin / Delete Additional Files Not Exposed to Maven上的示例。

  • 根据您的需要并使用以下内容来适应此处给出的<configuration>部分:

                        ...
                        <directory>src/main/java</directory>
                        ...
    
  • 添加一个<executions>部分,例如:

        ...
        <plugin>
            ...
            <executions>
                <execution>
                    <id>delete-files</id>
                    <!-- 'initialize' is the phase before 'generate-sources'
                          use 'verify' to execute it before 'install' -->
                    <phase>initialize</phase>
                    <goals>
                        <goal>clean</goal>
                    </goals>
                </execution>
            </executions>
            ...
    

结果将是:

...
[INFO] 
[INFO] --- maven-clean-plugin:3.1.0:clean (delete-files) @ so-51708371 ---
[INFO] Deleting ...path to workspace...\so-51708371\target
[INFO] Deleting ...path to workspace...\so-51708371\src\main\java (includes = [**/*.tmp, **/*.log], excludes = [**/important.log, **/another-important.log])
[INFO]
...