Exclude support in the maven plugin

This commit provides several options to exclude one or more
dependencies:

* excludes allows to specify an arbitrary number of exclude sub
  element defining the groupId and artifactId of the dependency
  to exclude
* excludedGroupIds defines the comma separated list of groupIds
  to exclude
* excludeArtifactIds defines the comma separated list of artifactIds
  to exclude

While any artifact can be excluded, this is designed to exclude
provided-scoped dependencies that should not be bundled in the
executable jar/war.

The outcome of java -jar myapp.jar should be consistent with the run
goal: these exclusions are therefore applied to the classpath that
the run goal computes to launch the application.

This commit also adds some integration tests and updates the
plugin's documentation

Fixes gh-649, gh-650 and gh-674
This commit is contained in:
Stephane Nicoll
2014-05-06 14:54:09 +02:00
parent 28bd87cbae
commit 15501eaafb
32 changed files with 1282 additions and 54 deletions

View File

@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.boot.maven.it</groupId>
<artifactId>run-exclude</artifactId>
<version>0.0.1.BUILD-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<excludes>
<exclude>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclude>
</excludes>
<excludeGroupIds>javax.servlet</excludeGroupIds>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,27 @@
package org.test;
public class SampleApplication {
public static void main(String[] args) {
if (isClassPresent("org.apache.log4j.Logger")) {
throw new IllegalStateException("Log4j was present and should not");
}
if (isClassPresent("javax.servlet.Servlet")) {
throw new IllegalStateException("servlet-api was present and should not");
}
System.out.println("I haz been run");
}
private static boolean isClassPresent(String className) {
try {
ClassLoader classLoader = SampleApplication.class.getClassLoader();
classLoader.loadClass(className);
return true;
}
catch (ClassNotFoundException e) {
return false;
}
}
}

View File

@@ -0,0 +1,3 @@
def file = new File(basedir, "build.log")
return file.text.contains("I haz been run")