Search in sources :

Example 1 with BuildInfoProperties

use of org.springframework.boot.gradle.tasks.buildinfo.BuildInfoProperties in project spring-boot by spring-projects.

the class SpringBootExtension method buildInfo.

/**
 * Creates a new {@link BuildInfo} task named {@code bootBuildInfo} and configures the
 * Java plugin's {@code classes} task to depend upon it. The task is passed to the
 * given {@code configurer} for further configuration.
 * <p>
 * By default, the task's destination dir will be a directory named {@code META-INF}
 * beneath the main source set's resources output directory, and the task's project
 * artifact will be the base name of the {@code bootWar} or {@code bootJar} task.
 * @param configurer the task configurer
 */
public void buildInfo(Action<BuildInfo> configurer) {
    TaskContainer tasks = this.project.getTasks();
    TaskProvider<BuildInfo> bootBuildInfo = tasks.register("bootBuildInfo", BuildInfo.class, this::configureBuildInfoTask);
    this.project.getPlugins().withType(JavaPlugin.class, (plugin) -> {
        tasks.named(JavaPlugin.CLASSES_TASK_NAME).configure((task) -> task.dependsOn(bootBuildInfo));
        this.project.afterEvaluate((evaluated) -> bootBuildInfo.configure((buildInfo) -> {
            BuildInfoProperties properties = buildInfo.getProperties();
            if (properties.getArtifact() == null) {
                properties.setArtifact(determineArtifactBaseName());
            }
        }));
    });
    if (configurer != null) {
        bootBuildInfo.configure(configurer);
    }
}
Also used : Action(org.gradle.api.Action) Project(org.gradle.api.Project) Jar(org.gradle.jvm.tasks.Jar) BuildInfo(org.springframework.boot.gradle.tasks.buildinfo.BuildInfo) JavaPlugin(org.gradle.api.plugins.JavaPlugin) BasePlugin(org.gradle.api.plugins.BasePlugin) File(java.io.File) SourceSet(org.gradle.api.tasks.SourceSet) TaskContainer(org.gradle.api.tasks.TaskContainer) TaskProvider(org.gradle.api.tasks.TaskProvider) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) Property(org.gradle.api.provider.Property) BuildInfoProperties(org.springframework.boot.gradle.tasks.buildinfo.BuildInfoProperties) TaskContainer(org.gradle.api.tasks.TaskContainer) BuildInfo(org.springframework.boot.gradle.tasks.buildinfo.BuildInfo) BuildInfoProperties(org.springframework.boot.gradle.tasks.buildinfo.BuildInfoProperties)

Aggregations

File (java.io.File)1 Action (org.gradle.api.Action)1 Project (org.gradle.api.Project)1 BasePlugin (org.gradle.api.plugins.BasePlugin)1 JavaPlugin (org.gradle.api.plugins.JavaPlugin)1 JavaPluginExtension (org.gradle.api.plugins.JavaPluginExtension)1 Property (org.gradle.api.provider.Property)1 SourceSet (org.gradle.api.tasks.SourceSet)1 TaskContainer (org.gradle.api.tasks.TaskContainer)1 TaskProvider (org.gradle.api.tasks.TaskProvider)1 Jar (org.gradle.jvm.tasks.Jar)1 BuildInfo (org.springframework.boot.gradle.tasks.buildinfo.BuildInfo)1 BuildInfoProperties (org.springframework.boot.gradle.tasks.buildinfo.BuildInfoProperties)1