Add option to exclude devtools from fat jar
Add an `excludeDevtools` property to both the Maven and Gradle plugin that removes `org.springframework.boot:spring-boot-devtools` (if necessary) when repackaging the application. Closes gh-3171
This commit is contained in:
committed by
Phillip Webb
parent
e2fc30ef24
commit
e79ef9b73b
@@ -38,6 +38,7 @@ import org.springframework.boot.loader.tools.Layouts;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Dave Syer
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class SpringBootPluginExtension {
|
||||
|
||||
@@ -87,6 +88,11 @@ public class SpringBootPluginExtension {
|
||||
*/
|
||||
Set<String> requiresUnpack;
|
||||
|
||||
/**
|
||||
* Whether Spring Boot Devtools should be excluded from the fat jar.
|
||||
*/
|
||||
boolean excludeDevtools = false;
|
||||
|
||||
/**
|
||||
* Location of an agent jar to attach to the VM when running the application with
|
||||
* runJar task.
|
||||
@@ -186,6 +192,14 @@ public class SpringBootPluginExtension {
|
||||
this.requiresUnpack = requiresUnpack;
|
||||
}
|
||||
|
||||
public boolean isExcludeDevtools() {
|
||||
return this.excludeDevtools;
|
||||
}
|
||||
|
||||
public void setExcludeDevtools(boolean excludeDevtools) {
|
||||
this.excludeDevtools = excludeDevtools;
|
||||
}
|
||||
|
||||
public File getAgent() {
|
||||
return this.agent;
|
||||
}
|
||||
|
||||
@@ -155,12 +155,26 @@ class ProjectLibraries implements Libraries {
|
||||
if (libraries != null) {
|
||||
Set<String> duplicates = getDuplicates(libraries);
|
||||
for (GradleLibrary library : libraries) {
|
||||
library.setIncludeGroupName(duplicates.contains(library.getName()));
|
||||
callback.library(library);
|
||||
if (!isExcluded(library)) {
|
||||
library.setIncludeGroupName(duplicates.contains(library.getName()));
|
||||
callback.library(library);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isExcluded(GradleLibrary library) {
|
||||
if (this.extension.isExcludeDevtools() && isDevToolsJar(library)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isDevToolsJar(GradleLibrary library) {
|
||||
return "org.springframework.boot".equals(library.getGroup())
|
||||
&& library.getName().startsWith("spring-boot-devtools");
|
||||
}
|
||||
|
||||
private Set<String> getDuplicates(Set<GradleLibrary> libraries) {
|
||||
Set<String> duplicates = new HashSet<String>();
|
||||
Set<String> seen = new HashSet<String>();
|
||||
@@ -187,6 +201,10 @@ class ProjectLibraries implements Libraries {
|
||||
this.includeGroupName = includeGroupName;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return this.group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
String name = super.getName();
|
||||
|
||||
Reference in New Issue
Block a user