From a8706962d45197114291568cd38a8e2d861de4c2 Mon Sep 17 00:00:00 2001 From: Yanming Zhou Date: Fri, 1 Sep 2023 10:05:26 +0800 Subject: [PATCH 1/2] Use project.getLayout().getBuildDirectory() instead of getBuildDir() See gh-37167 --- .../boot/gradle/plugin/ApplicationPluginAction.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ApplicationPluginAction.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ApplicationPluginAction.java index 6d6ce030682d..e9030e83dcc5 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ApplicationPluginAction.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ApplicationPluginAction.java @@ -16,7 +16,6 @@ package org.springframework.boot.gradle.plugin; -import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.io.StringWriter; @@ -79,7 +78,7 @@ private void configureCreateStartScripts(Project project, JavaApplication javaAp } }); createStartScripts.getConventionMapping() - .map("outputDir", () -> new File(project.getBuildDir(), "bootScripts")); + .map("outputDir", () -> project.getLayout().getBuildDirectory().dir("bootScripts").get().getAsFile()); createStartScripts.getConventionMapping().map("applicationName", javaApplication::getApplicationName); createStartScripts.getConventionMapping().map("defaultJvmOpts", javaApplication::getApplicationDefaultJvmArgs); } From a77863245d8637a187fd4e4a772ced1e4ba2da73 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 1 Sep 2023 12:50:01 +0100 Subject: [PATCH 2/2] Polish "Use project.getLayout().getBuildDirectory() instead of getBuildDir()" See gh-37167 --- .../spring-boot-tools/spring-boot-gradle-plugin/build.gradle | 2 +- .../boot/gradle/tasks/buildinfo/BuildInfo.java | 5 +++-- .../BuildInfoIntegrationTests-basicExecution.gradle | 1 - ...IntegrationTests-removePropertiesUsingEmptyStrings.gradle | 1 - ...ildInfoIntegrationTests-removePropertiesUsingNulls.gradle | 1 - ...otJarIntegrationTests-explodedApplicationClasspath.gradle | 2 +- .../MavenIntegrationTests-bootJarCanBeUploaded.gradle | 2 +- .../MavenIntegrationTests-bootWarCanBeUploaded.gradle | 2 +- ...enPublishingIntegrationTests-bootJarCanBePublished.gradle | 2 +- ...enPublishingIntegrationTests-bootWarCanBePublished.gradle | 2 +- 10 files changed, 9 insertions(+), 11 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/build.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/build.gradle index 6520bb4270a0..5bdfacd6ef64 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/build.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/build.gradle @@ -48,7 +48,7 @@ gradlePlugin { } task preparePluginValidationClasses(type: Copy) { - destinationDir = file("$buildDir/classes/java/pluginValidation") + destinationDir = layout.buildDirectory.dir("classes/java/pluginValidation").get().asFile from(sourceSets.main.output.classesDirs) { exclude "**/CreateBootStartScripts.class" } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfo.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfo.java index b9b53ed36a5a..6c61112f8398 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfo.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfo.java @@ -22,9 +22,9 @@ import java.util.Map; import org.gradle.api.Action; -import org.gradle.api.Project; import org.gradle.api.Task; import org.gradle.api.file.DirectoryProperty; +import org.gradle.api.file.ProjectLayout; import org.gradle.api.internal.ConventionTask; import org.gradle.api.tasks.Nested; import org.gradle.api.tasks.OutputDirectory; @@ -75,7 +75,8 @@ public void generateBuildProperties() { /** * Returns the directory to which the {@code build-info.properties} file will be - * written. Defaults to the {@link Project#getBuildDir() Project's build directory}. + * written. Defaults to the {@link ProjectLayout#getBuildDirectory() Project's build + * directory}. * @return the destination directory */ @OutputDirectory diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoIntegrationTests-basicExecution.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoIntegrationTests-basicExecution.gradle index 826d2e21e338..eb5d189c6a4b 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoIntegrationTests-basicExecution.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoIntegrationTests-basicExecution.gradle @@ -5,7 +5,6 @@ plugins { version = '0.1.0' task buildInfo(type: org.springframework.boot.gradle.tasks.buildinfo.BuildInfo) { - destinationDir project.buildDir properties { artifact = 'foo' group = 'foo' diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoIntegrationTests-removePropertiesUsingEmptyStrings.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoIntegrationTests-removePropertiesUsingEmptyStrings.gradle index f14ef603c3d3..30ee02e9e493 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoIntegrationTests-removePropertiesUsingEmptyStrings.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoIntegrationTests-removePropertiesUsingEmptyStrings.gradle @@ -6,7 +6,6 @@ group = 'foo' version = '0.1.0' task buildInfo(type: org.springframework.boot.gradle.tasks.buildinfo.BuildInfo) { - destinationDir project.buildDir properties { group = '' artifact = '' diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoIntegrationTests-removePropertiesUsingNulls.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoIntegrationTests-removePropertiesUsingNulls.gradle index 0ec0aba36c48..9adb0a42cb09 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoIntegrationTests-removePropertiesUsingNulls.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoIntegrationTests-removePropertiesUsingNulls.gradle @@ -6,7 +6,6 @@ group = 'foo' version = '0.1.0' task buildInfo(type: org.springframework.boot.gradle.tasks.buildinfo.BuildInfo) { - destinationDir project.buildDir properties { group = null artifact = null diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-explodedApplicationClasspath.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-explodedApplicationClasspath.gradle index f97b7df5b6bd..d4fb21f8c9f0 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-explodedApplicationClasspath.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-explodedApplicationClasspath.gradle @@ -15,7 +15,7 @@ dependencies { task explode(type: Sync) { dependsOn(bootJar) - destinationDir = file("$buildDir/exploded") + destinationDir = layout.buildDirectory.dir("exploded").get().asFile from zipTree(files(bootJar).singleFile) } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/MavenIntegrationTests-bootJarCanBeUploaded.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/MavenIntegrationTests-bootJarCanBeUploaded.gradle index 06fddc9cf194..427c958388b7 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/MavenIntegrationTests-bootJarCanBeUploaded.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/MavenIntegrationTests-bootJarCanBeUploaded.gradle @@ -14,7 +14,7 @@ version = '1.0' uploadBootArchives { repositories { mavenDeployer { - repository(url: "file:${buildDir}/repo") + repository(url: "file:${layout.buildDirectory.dir("repo").get().asFile}") } } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/MavenIntegrationTests-bootWarCanBeUploaded.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/MavenIntegrationTests-bootWarCanBeUploaded.gradle index 5a3b86ddff1c..ee0a2e37d382 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/MavenIntegrationTests-bootWarCanBeUploaded.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/MavenIntegrationTests-bootWarCanBeUploaded.gradle @@ -14,7 +14,7 @@ version = '1.0' uploadBootArchives { repositories { mavenDeployer { - repository(url: "file:${buildDir}/repo") + repository(url: "file:${layout.buildDirectory.dir("repo").get().asFile}") } } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/MavenPublishingIntegrationTests-bootJarCanBePublished.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/MavenPublishingIntegrationTests-bootJarCanBePublished.gradle index 4c0506b7dbb3..f2d3d60c77c2 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/MavenPublishingIntegrationTests-bootJarCanBePublished.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/MavenPublishingIntegrationTests-bootJarCanBePublished.gradle @@ -14,7 +14,7 @@ version = '1.0' publishing { repositories { maven { - url "${buildDir}/repo" + url = layout.buildDirectory.dir("repo") } } publications { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/MavenPublishingIntegrationTests-bootWarCanBePublished.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/MavenPublishingIntegrationTests-bootWarCanBePublished.gradle index cf6d104d42ee..085f9373affc 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/MavenPublishingIntegrationTests-bootWarCanBePublished.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/MavenPublishingIntegrationTests-bootWarCanBePublished.gradle @@ -14,7 +14,7 @@ version = '1.0' publishing { repositories { maven { - url "${buildDir}/repo" + url = layout.buildDirectory.dir("repo") } } publications {