7

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.

Atais
  • 10,857
  • 6
  • 71
  • 111
  • 1
    run `mvn` command with `-X` option to see full logs. – Fran Montero Sep 01 '15 at 10:26
  • 1
    @FranMontero see update – Atais Sep 01 '15 at 10:42
  • You have not defined what to include nor what's excluded...See the [example in the documentation](http://maven.apache.org/plugins/maven-clean-plugin/examples/delete_additional_files.html). BTW: Just try `mvn -D clean.verbose=true package` Apart from that the output shows all configuration parts inclusive those which are defaults for the plugin. – khmarbaise Sep 01 '15 at 10:42
  • 1
    @khmarbaise because I want to remove the directory, not it's content. Why one folder is deleted OK and another is not? – Atais Sep 01 '15 at 10:44
  • Sorry...you wan't to remove a directory without removing it's content ? I assume i misunderstand a thing but from my point of view it does not make sense to try to delete a directory without removing it's content. – khmarbaise Sep 01 '15 at 10:45
  • @khmarbaise You do not need to specify the content of the folder. Obviously, what is inside should be deleted. – Atais Sep 01 '15 at 10:49

1 Answers1

10

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.

Atais
  • 10,857
  • 6
  • 71
  • 111
  • 1
    On the same note, I had an empty plugin definition on the parent. I deleted the `maven-clean-plugin` from the parent and my child clean worked. – Ruan Mendes Jun 26 '19 at 14:30