Search in sources :

Example 1 with BootJar

use of org.springframework.boot.gradle.tasks.bundling.BootJar in project spring-boot by spring-projects.

the class JavaPluginAction method configureBootJarTask.

private TaskProvider<BootJar> configureBootJarTask(Project project) {
    SourceSet mainSourceSet = javaPluginExtension(project).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
    Configuration developmentOnly = project.getConfigurations().getByName(SpringBootPlugin.DEVELOPMENT_ONLY_CONFIGURATION_NAME);
    Configuration productionRuntimeClasspath = project.getConfigurations().getByName(SpringBootPlugin.PRODUCTION_RUNTIME_CLASSPATH_CONFIGURATION_NAME);
    Callable<FileCollection> classpath = () -> mainSourceSet.getRuntimeClasspath().minus((developmentOnly.minus(productionRuntimeClasspath))).filter(new JarTypeFileSpec());
    TaskProvider<ResolveMainClassName> resolveMainClassName = ResolveMainClassName.registerForTask(SpringBootPlugin.BOOT_JAR_TASK_NAME, project, classpath);
    return project.getTasks().register(SpringBootPlugin.BOOT_JAR_TASK_NAME, BootJar.class, (bootJar) -> {
        bootJar.setDescription("Assembles an executable jar archive containing the main classes and their dependencies.");
        bootJar.setGroup(BasePlugin.BUILD_GROUP);
        bootJar.classpath(classpath);
        Provider<String> manifestStartClass = project.provider(() -> (String) bootJar.getManifest().getAttributes().get("Start-Class"));
        bootJar.getMainClass().convention(resolveMainClassName.flatMap((resolver) -> manifestStartClass.isPresent() ? manifestStartClass : resolveMainClassName.get().readMainClassName()));
    });
}
Also used : BootRun(org.springframework.boot.gradle.tasks.run.BootRun) JavaToolchainService(org.gradle.jvm.toolchain.JavaToolchainService) Callable(java.util.concurrent.Callable) JavaPlugin(org.gradle.api.plugins.JavaPlugin) BasePlugin(org.gradle.api.plugins.BasePlugin) FileCollection(org.gradle.api.file.FileCollection) ApplicationPlugin(org.gradle.api.plugins.ApplicationPlugin) LibraryElements(org.gradle.api.attributes.LibraryElements) SourceSet(org.gradle.api.tasks.SourceSet) BootBuildImage(org.springframework.boot.gradle.tasks.bundling.BootBuildImage) Bundling(org.gradle.api.attributes.Bundling) Configuration(org.gradle.api.artifacts.Configuration) Task(org.gradle.api.Task) Provider(org.gradle.api.provider.Provider) AttributeContainer(org.gradle.api.attributes.AttributeContainer) TaskProvider(org.gradle.api.tasks.TaskProvider) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) BootJar(org.springframework.boot.gradle.tasks.bundling.BootJar) Usage(org.gradle.api.attributes.Usage) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) LazyPublishArtifact(org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact) Jar(org.gradle.api.tasks.bundling.Jar) Action(org.gradle.api.Action) Project(org.gradle.api.Project) Set(java.util.Set) File(java.io.File) JavaToolchainSpec(org.gradle.jvm.toolchain.JavaToolchainSpec) List(java.util.List) ObjectFactory(org.gradle.api.model.ObjectFactory) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) Collections(java.util.Collections) Plugin(org.gradle.api.Plugin) StringUtils(org.springframework.util.StringUtils) SourceSet(org.gradle.api.tasks.SourceSet) Configuration(org.gradle.api.artifacts.Configuration) FileCollection(org.gradle.api.file.FileCollection)

Aggregations

File (java.io.File)1 Collections (java.util.Collections)1 List (java.util.List)1 Set (java.util.Set)1 Callable (java.util.concurrent.Callable)1 Action (org.gradle.api.Action)1 Plugin (org.gradle.api.Plugin)1 Project (org.gradle.api.Project)1 Task (org.gradle.api.Task)1 Configuration (org.gradle.api.artifacts.Configuration)1 AttributeContainer (org.gradle.api.attributes.AttributeContainer)1 Bundling (org.gradle.api.attributes.Bundling)1 LibraryElements (org.gradle.api.attributes.LibraryElements)1 Usage (org.gradle.api.attributes.Usage)1 FileCollection (org.gradle.api.file.FileCollection)1 LazyPublishArtifact (org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact)1 ObjectFactory (org.gradle.api.model.ObjectFactory)1 ApplicationPlugin (org.gradle.api.plugins.ApplicationPlugin)1 BasePlugin (org.gradle.api.plugins.BasePlugin)1 JavaPlugin (org.gradle.api.plugins.JavaPlugin)1