Tweaks for boot gradle plugin
Fixes gh-152. ... to ease excluding dependencies eckage changed to bootRepackage - Register BootRepackage order to use task foo(type: BootRepackage){} - Allow user to use customConfiguration configurations { hadoopruntime.exclude group: 'log4j' hadoopruntime.exclude group: 'org.slf4j' hadoopruntime.exclude group: 'org.apache.hadoop' hadoopruntime.exclude group: 'org.apache.hive' hadoopruntime.exclude group: 'commons-logging' hadoopruntime.exclude group: 'org.codehaus.jettison' hadoopruntime.exclude group: 'com.thoughtworks.xstream' } dependencies { compile "org.springframework.batch:spring-batch-core:$springBatchVersion" compile "org.springframework.batch:spring-batch-infrastructure:$springBatchVersion" compile "org.springframework.data:spring-yarn-batch:$springDataVersion" compile "org.springframework.data:spring-yarn-boot:$springDataVersion" runtime "org.springframework.data:spring-data-hadoop:$springDataVersion" runtime "org.springframework.data:spring-data-hadoop-core:$springDataVersion" runtime "log4j:log4j:$log4jVersion" runtime "org.slf4j:slf4j-log4j12:$slf4jVersion" testCompile "org.springframework.data:spring-yarn-test:$springDataVersion" testCompile "org.hamcrest:hamcrest-core:$hamcrestVersion" testCompile "org.hamcrest:hamcrest-library:$hamcrestVersion" hadoopruntime configurations.runtime } springBoot { backupSource = true customConfiguration = 'hadoopruntime' } task appmasterJar(type: Jar) { appendix = 'appmaster' from sourceSets.main.output exclude('**/*Container*') exclude('**/*Client*') } task clientJar(type: Jar) { appendix = 'client' from sourceSets.main.output exclude('**/*Appmaster*') exclude('**/*Container*') } task clientBoot(type: BootRepackage, dependsOn: clientJar) { withJarTask = clientJar } task appmasterBoot(type: BootRepackage, dependsOn: appmasterJar) { customConfiguration = "hadoopruntime" withJarTask = appmasterJar } //jar.enabled = false //bootRepackage.enabled = false task bootJars bootJars.dependsOn = [clientBoot,containerBoot,appmasterBoot] build.dependsOn(clientBoot) build.dependsOn(containerBoot) build.dependsOn(appmasterBoot) //build.dependsOn(bootJars)
This commit is contained in:
parent
ed8d161d33
commit
4c9c2b8dcf
|
@ -31,7 +31,7 @@ import org.springframework.boot.gradle.task.RunJar;
|
|||
*/
|
||||
public class SpringBootPlugin implements Plugin<Project> {
|
||||
|
||||
private static final String REPACKAGE_TASK_NAME = "repackage";
|
||||
private static final String REPACKAGE_TASK_NAME = "bootRepackage";
|
||||
|
||||
private static final String RUN_JAR_TASK_NAME = "runJar";
|
||||
|
||||
|
@ -40,6 +40,11 @@ public class SpringBootPlugin implements Plugin<Project> {
|
|||
project.getPlugins().apply(BasePlugin.class);
|
||||
project.getPlugins().apply(JavaPlugin.class);
|
||||
project.getExtensions().create("springBoot", SpringBootPluginExtension.class);
|
||||
|
||||
// register BootRepackage so that we can use
|
||||
// task foo(type: BootRepackage) {}
|
||||
project.getExtensions().getExtraProperties()
|
||||
.set("BootRepackage", Repackage.class);
|
||||
Repackage packageTask = addRepackageTask(project);
|
||||
ensureTaskRunsOnAssembly(project, packageTask);
|
||||
addRunJarTask(project);
|
||||
|
|
|
@ -59,6 +59,11 @@ public class SpringBootPluginExtension {
|
|||
*/
|
||||
String providedConfiguration
|
||||
|
||||
/**
|
||||
* The name of the custom configuration to use.
|
||||
*/
|
||||
String customConfiguration
|
||||
|
||||
/**
|
||||
* If the original source archive should be backed-up before being repackaged.
|
||||
*/
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
package org.springframework.boot.gradle.task;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -21,6 +20,7 @@ class ProjectLibraries implements Libraries {
|
|||
private final Project project;
|
||||
|
||||
private String providedConfigurationName = "providedRuntime";
|
||||
private String customConfigurationName = null;
|
||||
|
||||
/**
|
||||
* Create a new {@link ProjectLibraries} instance of the specified {@link Project}.
|
||||
|
@ -40,24 +40,39 @@ class ProjectLibraries implements Libraries {
|
|||
this.providedConfigurationName = providedConfigurationName;
|
||||
}
|
||||
|
||||
public void setCustomConfigurationName(String customConfigurationName) {
|
||||
this.customConfigurationName = customConfigurationName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doWithLibraries(LibraryCallback callback) throws IOException {
|
||||
|
||||
FileCollection compile = this.project.getConfigurations().getByName("compile");
|
||||
FileCollection custom = this.customConfigurationName != null ? this.project
|
||||
.getConfigurations().findByName(this.customConfigurationName) : null;
|
||||
|
||||
FileCollection runtime = this.project.getConfigurations().getByName("runtime");
|
||||
runtime = runtime.minus(compile);
|
||||
if (custom != null) {
|
||||
libraries(LibraryScope.CUSTOM, custom, callback);
|
||||
}
|
||||
else {
|
||||
FileCollection compile = this.project.getConfigurations()
|
||||
.getByName("compile");
|
||||
|
||||
FileCollection provided = this.project.getConfigurations().findByName(
|
||||
this.providedConfigurationName);
|
||||
if (provided != null) {
|
||||
compile = compile.minus(provided);
|
||||
runtime = runtime.minus(provided);
|
||||
FileCollection runtime = this.project.getConfigurations()
|
||||
.getByName("runtime");
|
||||
runtime = runtime.minus(compile);
|
||||
|
||||
FileCollection provided = this.project.getConfigurations().findByName(
|
||||
this.providedConfigurationName);
|
||||
if (provided != null) {
|
||||
compile = compile.minus(provided);
|
||||
runtime = runtime.minus(provided);
|
||||
}
|
||||
|
||||
libraries(LibraryScope.COMPILE, compile, callback);
|
||||
libraries(LibraryScope.RUNTIME, runtime, callback);
|
||||
libraries(LibraryScope.PROVIDED, provided, callback);
|
||||
}
|
||||
|
||||
libraries(LibraryScope.COMPILE, compile, callback);
|
||||
libraries(LibraryScope.RUNTIME, runtime, callback);
|
||||
libraries(LibraryScope.PROVIDED, provided, callback);
|
||||
}
|
||||
|
||||
private void libraries(LibraryScope scope, FileCollection files,
|
||||
|
|
|
@ -34,6 +34,18 @@ import org.springframework.boot.loader.tools.Repackager;
|
|||
*/
|
||||
public class Repackage extends DefaultTask {
|
||||
|
||||
private String customConfiguration;
|
||||
|
||||
private Object withJarTask;
|
||||
|
||||
public void setCustomConfiguration(String customConfiguration) {
|
||||
this.customConfiguration = customConfiguration;
|
||||
}
|
||||
|
||||
public void setWithJarTask(Object withJarTask) {
|
||||
this.withJarTask = withJarTask;
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
public void repackage() {
|
||||
Project project = getProject();
|
||||
|
@ -43,10 +55,23 @@ public class Repackage extends DefaultTask {
|
|||
if (extension.getProvidedConfiguration() != null) {
|
||||
libraries.setProvidedConfigurationName(extension.getProvidedConfiguration());
|
||||
}
|
||||
if (this.customConfiguration != null) {
|
||||
libraries.setCustomConfigurationName(this.customConfiguration);
|
||||
}
|
||||
else if (extension.getCustomConfiguration() != null) {
|
||||
libraries.setCustomConfigurationName(extension.getCustomConfiguration());
|
||||
}
|
||||
project.getTasks().withType(Jar.class, new Action<Jar>() {
|
||||
|
||||
@Override
|
||||
public void execute(Jar archive) {
|
||||
// if withJarTask is set, compare tasks
|
||||
// and bail out if we didn't match
|
||||
if (Repackage.this.withJarTask != null
|
||||
&& !archive.equals(Repackage.this.withJarTask)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ("".equals(archive.getClassifier())) {
|
||||
File file = archive.getArchivePath();
|
||||
if (file.exists()) {
|
||||
|
|
|
@ -55,4 +55,14 @@ public interface LibraryScope {
|
|||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Marker for custom scope when custom configuration is used.
|
||||
*/
|
||||
public static final LibraryScope CUSTOM = new LibraryScope() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "custom";
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue