在 maven generate-sources 或 maven install 期间删除文件夹
Remove folder during maven generate-sources or maven install
我正在尝试在执行 generate-sources
或 install
之前删除文件夹。我已经在 clean
期间对 src/main/java
下的文件夹进行了此操作,但我也想在不同的时刻尝试,只是因为我确定不可能忘记删除一些 file/folder。这是怎么做到的?
参见 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]
...
我正在尝试在执行 generate-sources
或 install
之前删除文件夹。我已经在 clean
期间对 src/main/java
下的文件夹进行了此操作,但我也想在不同的时刻尝试,只是因为我确定不可能忘记删除一些 file/folder。这是怎么做到的?
参见 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] ...