1

I'm trying to exclude a complete folder to be embedded within a JAR. I found the following directive which works like a charm :

<plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <excludes>
                    <exclude>**/unwantedJars/**</exclude>
                </excludes>
            </configuration>
        </plugin>
  </plugins>  

So, when running mvn clean install, no problem, I get a JAR without the unwanted folder.

However, I have several projects which needs to include this directive (together with other common configuration), so I'm using a parent POM project. Everything is working well, apart the above directive. As soon as I move this exclude part to the parent POM definition, it doesn't work anymore.

Strange thing is that if I compare the effective POM of the 2 configuration, they're strictly identical!

What's the difference between having this directive on the POM of the current project or in the parent POM?

BartoszKP
  • 34,786
  • 15
  • 102
  • 130
hublo
  • 1,010
  • 2
  • 12
  • 33
  • Why do you need to exclude those files/folders from packaging? – khmarbaise Aug 27 '15 at 09:08
  • Well, this folder contains several JARs required only at Design time (BIRT), but absolutely useless once deployed on the running environment. Embedding them increase the size of the final JAR with a relatively big ratio ... – hublo Aug 27 '15 at 11:54

1 Answers1

0

You need to use pluginManagement

parent-pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      http://maven.apache.org/xsd/maven-4.0.0.xsd">
  ...
  <build>
    ...
    <pluginManagement>
      <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <excludes>
                    <exclude>**/unwantedJars/**</exclude>
                </excludes>
            </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
    ...
  </build>
</project>

child-pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      http://maven.apache.org/xsd/maven-4.0.0.xsd">
  ...
  <build>
    ...
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
      </plugin>
    </plugins>
    ...
  </build>
</project>
Yuri G.
  • 4,323
  • 1
  • 17
  • 32
  • thanks for the suggestion, but unfortunately it didn't help. However, coming back on the initial post ... how can we explain that 2 identical effective POM can result in 2 different results ? – hublo Sep 01 '15 at 09:42