java - maven-clean-plugin 没有删除所有给定的目录

标签 java maven maven-3 maven-plugin maven-clean-plugin

在我的项目 .pom 中,我设置了 maven-clean-plugin 如下:

<plugin>
  <artifactId>maven-clean-plugin</artifactId>
  <version>2.6.1</version>
  <configuration>
    <filesets>
      <fileset>
        <directory>src/main/webapp/bower_components</directory>
      </fileset>
      <fileset>
        <directory>node_modules</directory>
      </fileset>
      <fileset>
        <directory>node</directory>
      </fileset>
    </filesets>
  </configuration>
 </plugin>

插件的目的是删除由 frontend-maven-plugin 创建的目录。无论如何,最后一个工作正常。


问题

现在的问题是,无缘无故地,上述文件夹之一永远不会被删除。而且它始终是“中间”的那个。我添加了 3 个 filesets,但始终没有删除第 2 个,查看日志:

[INFO] Deleting /src/main/webapp/bower_components (includes = [], excludes = [])
[INFO] Deleting /node_modules (includes = [.bindings], excludes = [])
[INFO] Deleting /node (includes = [], excludes = [])

如果我更改文件夹的顺序:

[INFO] Deleting /src/main/webapp/bower_components (includes = [], excludes = [])
[INFO] Deleting /node (includes = [.bindings], excludes = [])
[INFO] Deleting /node_modules (includes = [], excludes = [])

而且第二个选项始终包含此部分: includes = [.bindings] 我相信这会导致文件夹未被删除。

为什么会这样,如何解决?


编辑,调试日志

mvn -X clean 结果,我认为这是它中断的地方:

http://pastebin.com/ep1i2Bjk

解析 pom.xml 后,它会读取带有此参数的配置。 但是,我并没有把它放在那里。

最佳答案

好的,我找到问题了!它实际上是插件中的一个错误,并且已经被报告过。它会影响 maven-clean-plugin 2.6.1

这是我这边的配置错误,请继续阅读解决方案。

情况

您有一个父项目和一个子项目,两者都必须使用该插件。

现在;

  • 在父项目中指定一些文件集。
  • 在子项目中指定一些文件集。

我认为是预期的:

插件读取 parent 和 child 的文件集并全部清理。

会发生什么:

插件使用子文件集覆盖父文件集。文件集按顺序被覆盖。但是文件集的父配置没有被清除!


我的情况: 父 .pom:

<filesets>
   <fileset>
      <directory>test-output</directory>
   </fileset>
   <fileset>
     <directory>${basedir}/</directory>
     <includes>
        <include>.bindings</include>
     </includes> 
   </fileset>
</filesets>

child pom:

<filesets>
    <fileset>
        <directory>node</directory>
    </fileset>
    <fileset>
        <directory>node_modules</directory>
    </fileset>
    <fileset>
        <directory>src/main/webapp/bower_components</directory>
    </fileset>
</filesets>

并有了以上信息;插件读取的配置是:

<filesets>
    <fileset>
        <directory>node</directory>
    </fileset>
    <fileset>
        <directory>node_modules</directory>
        <includes>
            <include>.bindings</include>
        </includes>
    </fileset>
    <fileset>
        <directory>src/main/webapp/bower_components</directory>
    </fileset>
</filesets>

而不是包含 5 个文件集的配置。

错误报告 https://issues.apache.org/jira/browse/MCLEAN-64

已解决

For configuration there are some magic attributes to instruct how xml elements should be combined. In this case add combine.children="append" to the filesets tag. More details about this can be found on the POM Reference page. http://maven.apache.org/pom.html

值得一提的是,在 child 的项目.pom中设置combine.children="append"即可。

关于java - maven-clean-plugin 没有删除所有给定的目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32329141/

相关文章:

java - MySQL 连接到 java 应用程序

java - Maven编译导致ClassNotFoundException

maven - 如何以编程方式使用存储在 Nexus 中的旧快照 Artifact

maven - Axis2 数据绑定(bind) jaxbri + Maven : JAX-B RI JARs not on classpath

java - 访问 Firebase 中的 key

java - Android Files : if I copy a . zip 文件到/sdcard/Download,uri 会错误

tomcat - maven tomcat 部署插件,这样就不会完成重建

java - Maven : Multi Module order

java - 存储对象以供以后在 java 中使用

java - Netbeans Maven 项目 - 其他来源未出现