Skip to content

Commit 7613e91

Browse files
committed
Remove calls to deprecated Project.getBuildDir()
Closes gh-42728
1 parent a306065 commit 7613e91

File tree

8 files changed

+60
-31
lines changed

8 files changed

+60
-31
lines changed

buildSrc/src/main/java/org/springframework/boot/build/AsciidoctorConventions.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,14 @@ private void configureOptions(AbstractAsciidoctorTask asciidoctorTask) {
147147
asciidoctorTask.options(Collections.singletonMap("doctype", "book"));
148148
}
149149

150-
private Sync createSyncDocumentationSourceTask(Project project, AbstractAsciidoctorTask asciidoctorTask) {
150+
private void createSyncDocumentationSourceTask(Project project, AbstractAsciidoctorTask asciidoctorTask) {
151151
Sync syncDocumentationSource = project.getTasks()
152152
.create("syncDocumentationSourceFor" + StringUtils.capitalize(asciidoctorTask.getName()), Sync.class);
153-
File syncedSource = new File(project.getBuildDir(), "docs/src/" + asciidoctorTask.getName());
153+
File syncedSource = project.getLayout()
154+
.getBuildDirectory()
155+
.dir("docs/src/" + asciidoctorTask.getName())
156+
.get()
157+
.getAsFile();
154158
syncDocumentationSource.setDestinationDir(syncedSource);
155159
syncDocumentationSource.from("src/docs/");
156160
asciidoctorTask.dependsOn(syncDocumentationSource);
@@ -159,7 +163,6 @@ private Sync createSyncDocumentationSourceTask(Project project, AbstractAsciidoc
159163
.withPathSensitivity(PathSensitivity.RELATIVE)
160164
.withPropertyName("synced source");
161165
asciidoctorTask.setSourceDir(project.relativePath(new File(syncedSource, "asciidoc/")));
162-
return syncDocumentationSource;
163166
}
164167

165168
}

buildSrc/src/main/java/org/springframework/boot/build/MavenRepositoryPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class MavenRepositoryPlugin implements Plugin<Project> {
5858
public void apply(Project project) {
5959
project.getPlugins().apply(MavenPublishPlugin.class);
6060
PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
61-
File repositoryLocation = new File(project.getBuildDir(), "maven-repository");
61+
File repositoryLocation = project.getLayout().getBuildDirectory().dir("maven-repository").get().getAsFile();
6262
publishing.getRepositories().maven((mavenRepository) -> {
6363
mavenRepository.setName("project");
6464
mavenRepository.setUrl(repositoryLocation.toURI());

buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureCheck.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ public ArchitectureCheck() {
8282
noClassesShouldCallStepVerifierStepVerifyComplete(),
8383
noClassesShouldConfigureDefaultStepVerifierTimeout(), noClassesShouldCallCollectorsToList(),
8484
noClassesShouldCallURLEncoderWithStringEncoding(), noClassesShouldCallURLDecoderWithStringEncoding(),
85-
noClassesShouldCallStringToUpperCaseWithoutLocale(), noClassesShouldCallStringToLowerCaseWithoutLocale());
85+
noClassesShouldCallStringToUpperCaseWithoutLocale(),
86+
noClassesShouldCallStringToLowerCaseWithoutLocale());
8687
getRules().addAll(getProhibitObjectsRequireNonNull()
8788
.map((prohibit) -> prohibit ? noClassesShouldCallObjectsRequireNonNull() : Collections.emptyList()));
8889
getRuleDescriptions().set(getRules().map((rules) -> rules.stream().map(ArchRule::getDescription).toList()));

buildSrc/src/main/java/org/springframework/boot/build/autoconfigure/AutoConfigurationPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ public void apply(Project project) {
9393
.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
9494
task.setSourceSet(main);
9595
task.dependsOn(main.getClassesTaskName());
96-
task.getOutputFile().set(new File(project.getBuildDir(), "auto-configuration-metadata.properties"));
96+
task.getOutputFile()
97+
.set(project.getLayout().getBuildDirectory().file("auto-configuration-metadata.properties"));
9798
project.getArtifacts()
9899
.add(AutoConfigurationPlugin.AUTO_CONFIGURATION_METADATA_CONFIGURATION_NAME, task.getOutputFile(),
99100
(artifact) -> artifact.builtBy(task));

buildSrc/src/main/java/org/springframework/boot/build/bom/BomExtension.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,11 @@ public void effectiveBomArtifact() {
130130
.all((task) -> {
131131
Sync syncBom = this.project.getTasks().create("syncBom", Sync.class);
132132
syncBom.dependsOn(task);
133-
File generatedBomDir = new File(this.project.getBuildDir(), "generated/bom");
133+
File generatedBomDir = this.project.getLayout()
134+
.getBuildDirectory()
135+
.dir("generated/bom")
136+
.get()
137+
.getAsFile();
134138
syncBom.setDestinationDir(generatedBomDir);
135139
syncBom.from(((GenerateMavenPom) task).getDestination(), (pom) -> pom.rename((name) -> "pom.xml"));
136140
try {
@@ -139,7 +143,12 @@ public void effectiveBomArtifact() {
139143
getClass().getClassLoader().getResourceAsStream("effective-bom-settings.xml"),
140144
StandardCharsets.UTF_8))
141145
.replace("localRepositoryPath",
142-
new File(this.project.getBuildDir(), "local-m2-repository").getAbsolutePath());
146+
this.project.getLayout()
147+
.getBuildDirectory()
148+
.dir("local-m2-repository")
149+
.get()
150+
.getAsFile()
151+
.getAbsolutePath());
143152
syncBom.from(this.project.getResources().getText().fromString(settingsXmlContent),
144153
(settingsXml) -> settingsXml.rename((name) -> "settings.xml"));
145154
}
@@ -149,8 +158,11 @@ public void effectiveBomArtifact() {
149158
MavenExec generateEffectiveBom = this.project.getTasks()
150159
.create("generateEffectiveBom", MavenExec.class);
151160
generateEffectiveBom.getProjectDir().set(generatedBomDir);
152-
File effectiveBom = new File(this.project.getBuildDir(),
153-
"generated/effective-bom/" + this.project.getName() + "-effective-bom.xml");
161+
File effectiveBom = this.project.getLayout()
162+
.getBuildDirectory()
163+
.file("generated/effective-bom/" + this.project.getName() + "-effective-bom.xml")
164+
.get()
165+
.getAsFile();
154166
generateEffectiveBom.args("--settings", "settings.xml", "help:effective-pom",
155167
"-Doutput=" + effectiveBom);
156168
generateEffectiveBom.dependsOn(syncBom);

buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/MavenPluginPlugin.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,15 @@
5858
import org.gradle.api.component.ConfigurationVariantDetails;
5959
import org.gradle.api.component.SoftwareComponent;
6060
import org.gradle.api.file.CopySpec;
61+
import org.gradle.api.file.Directory;
6162
import org.gradle.api.file.DirectoryProperty;
6263
import org.gradle.api.file.FileCollection;
6364
import org.gradle.api.file.RegularFileProperty;
6465
import org.gradle.api.model.ObjectFactory;
6566
import org.gradle.api.plugins.JavaLibraryPlugin;
6667
import org.gradle.api.plugins.JavaPlugin;
6768
import org.gradle.api.plugins.JavaPluginExtension;
69+
import org.gradle.api.provider.Provider;
6870
import org.gradle.api.publish.PublishingExtension;
6971
import org.gradle.api.publish.maven.MavenPublication;
7072
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
@@ -170,11 +172,11 @@ private void addPopulateIntTestMavenRepositoryTask(Project project) {
170172
RuntimeClasspathMavenRepository runtimeClasspathMavenRepository = project.getTasks()
171173
.create("runtimeClasspathMavenRepository", RuntimeClasspathMavenRepository.class);
172174
runtimeClasspathMavenRepository.getOutputDir()
173-
.set(new File(project.getBuildDir(), "runtime-classpath-repository"));
175+
.set(project.getLayout().getBuildDirectory().dir("runtime-classpath-repository"));
174176
project.getDependencies()
175177
.components((components) -> components.all(MavenRepositoryComponentMetadataRule.class));
176178
Sync task = project.getTasks().create("populateTestMavenRepository", Sync.class);
177-
task.setDestinationDir(new File(project.getBuildDir(), "test-maven-repository"));
179+
task.setDestinationDir(project.getLayout().getBuildDirectory().dir("test-maven-repository").get().getAsFile());
178180
task.with(copyIntTestMavenRepositoryFiles(project, runtimeClasspathMavenRepository));
179181
task.dependsOn(project.getTasks().getByName(MavenRepositoryPlugin.PUBLISH_TO_PROJECT_REPOSITORY_TASK_NAME));
180182
project.getTasks().getByName(IntegrationTestPlugin.INT_TEST_TASK_NAME).dependsOn(task);
@@ -188,7 +190,7 @@ private CopySpec copyIntTestMavenRepositoryFiles(Project project,
188190
RuntimeClasspathMavenRepository runtimeClasspathMavenRepository) {
189191
CopySpec copySpec = project.copySpec();
190192
copySpec.from(project.getConfigurations().getByName(MavenRepositoryPlugin.MAVEN_REPOSITORY_CONFIGURATION_NAME));
191-
copySpec.from(new File(project.getBuildDir(), "maven-repository"));
193+
copySpec.from(project.getLayout().getBuildDirectory().dir("maven-repository"));
192194
copySpec.from(runtimeClasspathMavenRepository);
193195
return copySpec;
194196
}
@@ -197,29 +199,29 @@ private void addDocumentPluginGoalsTask(Project project, MavenExec generatePlugi
197199
DocumentPluginGoals task = project.getTasks().create("documentPluginGoals", DocumentPluginGoals.class);
198200
File pluginXml = new File(generatePluginDescriptorTask.getOutputs().getFiles().getSingleFile(), "plugin.xml");
199201
task.getPluginXml().set(pluginXml);
200-
task.getOutputDir().set(new File(project.getBuildDir(), "docs/generated/goals/"));
202+
task.getOutputDir().set(project.getLayout().getBuildDirectory().dir("docs/generated/goals/"));
201203
task.dependsOn(generatePluginDescriptorTask);
202204
}
203205

204206
private MavenExec addGenerateHelpMojoTask(Project project, Jar jarTask) {
205-
File helpMojoDir = new File(project.getBuildDir(), "help-mojo");
207+
Provider<Directory> helpMojoDir = project.getLayout().getBuildDirectory().dir("help-mojo");
206208
MavenExec task = createGenerateHelpMojoTask(project, helpMojoDir);
207209
task.dependsOn(createSyncHelpMojoInputsTask(project, helpMojoDir));
208210
includeHelpMojoInJar(jarTask, task);
209211
return task;
210212
}
211213

212-
private MavenExec createGenerateHelpMojoTask(Project project, File helpMojoDir) {
214+
private MavenExec createGenerateHelpMojoTask(Project project, Provider<Directory> helpMojoDir) {
213215
MavenExec task = project.getTasks().create("generateHelpMojo", MavenExec.class);
214216
task.getProjectDir().set(helpMojoDir);
215217
task.args("org.apache.maven.plugins:maven-plugin-plugin:3.6.1:helpmojo");
216-
task.getOutputs().dir(new File(helpMojoDir, "target/generated-sources/plugin"));
218+
task.getOutputs().dir(helpMojoDir.map((directory) -> directory.dir("target/generated-sources/plugin")));
217219
return task;
218220
}
219221

220-
private Sync createSyncHelpMojoInputsTask(Project project, File helpMojoDir) {
222+
private Sync createSyncHelpMojoInputsTask(Project project, Provider<Directory> helpMojoDir) {
221223
Sync task = project.getTasks().create("syncHelpMojoInputs", Sync.class);
222-
task.setDestinationDir(helpMojoDir);
224+
task.setDestinationDir(helpMojoDir.get().getAsFile());
223225
File pomFile = new File(project.getProjectDir(), "src/maven/resources/pom.xml");
224226
task.from(pomFile, (copy) -> replaceVersionPlaceholder(copy, project));
225227
return task;
@@ -231,8 +233,10 @@ private void includeHelpMojoInJar(Jar jarTask, JavaExec generateHelpMojoTask) {
231233
}
232234

233235
private MavenExec addGeneratePluginDescriptorTask(Project project, Jar jarTask, MavenExec generateHelpMojoTask) {
234-
File pluginDescriptorDir = new File(project.getBuildDir(), "plugin-descriptor");
235-
File generatedHelpMojoDir = new File(project.getBuildDir(), "generated/sources/helpMojo");
236+
Provider<Directory> pluginDescriptorDir = project.getLayout().getBuildDirectory().dir("plugin-descriptor");
237+
Provider<Directory> generatedHelpMojoDir = project.getLayout()
238+
.getBuildDirectory()
239+
.dir("generated/sources/helpMojo");
236240
SourceSet mainSourceSet = getMainSourceSet(project);
237241
project.getTasks().withType(Javadoc.class, this::setJavadocOptions);
238242
FormatHelpMojoSource formattedHelpMojoSource = createFormatHelpMojoSource(project, generateHelpMojoTask,
@@ -258,17 +262,18 @@ private void setJavadocOptions(Javadoc javadoc) {
258262
}
259263

260264
private FormatHelpMojoSource createFormatHelpMojoSource(Project project, MavenExec generateHelpMojoTask,
261-
File generatedHelpMojoDir) {
265+
Provider<Directory> generatedHelpMojoDir) {
262266
FormatHelpMojoSource formatHelpMojoSource = project.getTasks()
263267
.create("formatHelpMojoSource", FormatHelpMojoSource.class);
264268
formatHelpMojoSource.setGenerator(generateHelpMojoTask);
265269
formatHelpMojoSource.getOutputDir().set(generatedHelpMojoDir);
266270
return formatHelpMojoSource;
267271
}
268272

269-
private Sync createSyncPluginDescriptorInputs(Project project, File destination, SourceSet sourceSet) {
273+
private Sync createSyncPluginDescriptorInputs(Project project, Provider<Directory> destination,
274+
SourceSet sourceSet) {
270275
Sync pluginDescriptorInputs = project.getTasks().create("syncPluginDescriptorInputs", Sync.class);
271-
pluginDescriptorInputs.setDestinationDir(destination);
276+
pluginDescriptorInputs.setDestinationDir(destination.get().getAsFile());
272277
File pomFile = new File(project.getProjectDir(), "src/maven/resources/pom.xml");
273278
pluginDescriptorInputs.from(pomFile, (copy) -> replaceVersionPlaceholder(copy, project));
274279
pluginDescriptorInputs.from(sourceSet.getOutput().getClassesDirs(), (sync) -> sync.into("target/classes"));
@@ -277,12 +282,13 @@ private Sync createSyncPluginDescriptorInputs(Project project, File destination,
277282
return pluginDescriptorInputs;
278283
}
279284

280-
private MavenExec createGeneratePluginDescriptorTask(Project project, File mavenDir) {
285+
private MavenExec createGeneratePluginDescriptorTask(Project project, Provider<Directory> mavenDir) {
281286
MavenExec generatePluginDescriptor = project.getTasks().create("generatePluginDescriptor", MavenExec.class);
282287
generatePluginDescriptor.args("org.apache.maven.plugins:maven-plugin-plugin:3.6.1:descriptor");
283-
generatePluginDescriptor.getOutputs().dir(new File(mavenDir, "target/classes/META-INF/maven"));
288+
generatePluginDescriptor.getOutputs()
289+
.dir(mavenDir.map((directory) -> directory.dir("target/classes/META-INF/maven")));
284290
generatePluginDescriptor.getInputs()
285-
.dir(new File(mavenDir, "target/classes/org"))
291+
.dir(mavenDir.map((directory) -> directory.dir("target/classes/org")))
286292
.withPathSensitivity(PathSensitivity.RELATIVE)
287293
.withPropertyName("plugin classes");
288294
generatePluginDescriptor.getProjectDir().set(mavenDir);
@@ -298,7 +304,7 @@ private void addPrepareMavenBinariesTask(Project project) {
298304
TaskProvider<PrepareMavenBinaries> task = project.getTasks()
299305
.register("prepareMavenBinaries", PrepareMavenBinaries.class,
300306
(prepareMavenBinaries) -> prepareMavenBinaries.getOutputDir()
301-
.set(new File(project.getBuildDir(), "maven-binaries")));
307+
.set(project.getLayout().getBuildDirectory().dir("maven-binaries")));
302308
project.getTasks()
303309
.getByName(IntegrationTestPlugin.INT_TEST_TASK_NAME)
304310
.getInputs()

buildSrc/src/main/java/org/springframework/boot/build/starters/StarterPlugin.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@
1616

1717
package org.springframework.boot.build.starters;
1818

19-
import java.io.File;
2019
import java.util.Map;
2120
import java.util.TreeMap;
2221

2322
import org.gradle.api.Plugin;
2423
import org.gradle.api.Project;
2524
import org.gradle.api.artifacts.Configuration;
2625
import org.gradle.api.artifacts.ConfigurationContainer;
26+
import org.gradle.api.file.RegularFile;
2727
import org.gradle.api.plugins.JavaBasePlugin;
2828
import org.gradle.api.plugins.JavaLibraryPlugin;
2929
import org.gradle.api.plugins.JavaPlugin;
3030
import org.gradle.api.plugins.PluginContainer;
31+
import org.gradle.api.provider.Provider;
3132
import org.gradle.api.tasks.bundling.Jar;
3233

3334
import org.springframework.boot.build.ConventionsPlugin;
@@ -56,7 +57,7 @@ public void apply(Project project) {
5657
ConfigurationContainer configurations = project.getConfigurations();
5758
Configuration runtimeClasspath = configurations.getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME);
5859
starterMetadata.setDependencies(runtimeClasspath);
59-
File destination = new File(project.getBuildDir(), "starter-metadata.properties");
60+
Provider<RegularFile> destination = project.getLayout().getBuildDirectory().file("starter-metadata.properties");
6061
starterMetadata.getDestination().set(destination);
6162
configurations.create("starterMetadata");
6263
project.getArtifacts()

buildSrc/src/test/java/org/springframework/boot/build/architecture/ArchitectureCheckTests.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ void whenPackagesAreNotTangledTaskSucceedsAndWritesAnEmptyReport() throws Except
6060
}
6161

6262
File failureReport(ArchitectureCheck architectureCheck) {
63-
return new File(architectureCheck.getProject().getBuildDir(), "checkArchitecture/failure-report.txt");
63+
return architectureCheck.getProject()
64+
.getLayout()
65+
.getBuildDirectory()
66+
.file("checkArchitecture/failure-report.txt")
67+
.get()
68+
.getAsFile();
6469
}
6570

6671
@Test

0 commit comments

Comments
 (0)