Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven-clean-plugin is not removing all given directories

In my project .pom I set up the maven-clean-plugin like so:

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

The plugin purpose is to remove directories which are created by frontend-maven-plugin. Anyway the last one works OK.


Problem

Now the issue is that for no reason, one of the above folders is never removed. And it is always the one "in the middle". I added 3 filesets and always the 2nd one is not removed, see logs:

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

If I change folders' order:

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

And also the 2nd option always contains this part: includes = [.bindings] which I believe results in the folder not being deleted.

Why is that happening, and how to fix it?


EDIT, debug log

mvn -X clean result, I think this is where it breaks:

http://pastebin.com/ep1i2Bjk

After parsing the pom.xml it reads the configuration with this parameter. However, I did not put it there.

like image 766
Atais Avatar asked Sep 01 '15 10:09

Atais


1 Answers

OK I have found the issue! It is actually a bug in the plugin and is already reported. It affects the maven-clean-plugin 2.6.1.

It was my side misconfiguration, read on for the resolution.

Situation

You have a parent project and a child project, both have to use the plugin.

Now;

  • in parent project you specify some filesets.
  • in child project you specify some filesets.

What I think is expected:

Plugin read both parent's and child's filesets and cleans them all.

What happens:

Plugin OVERRIDES the parent's filesets with child's filesets. Filesets are overriden in order. HOWEVER the parents configuration for the fileset is not cleared!


My situation: Parent .pom:

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

Childs pom:

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

And with the above information; the config read by plugin is:

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

instead of a config with 5 filesets.

Bug report https://issues.apache.org/jira/browse/MCLEAN-64

RESOLVED

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

Worth mentioning is that it is enough to set combine.children="append" in child's project .pom.

like image 195
Atais Avatar answered Oct 27 '22 09:10

Atais