diff --git a/build.gradle b/build.gradle index 9da48942a2..83bfda6c17 100644 --- a/build.gradle +++ b/build.gradle @@ -38,3 +38,7 @@ allprojects { resolutionStrategy.cacheChangingModulesFor 0, "minutes" } } + +tasks.named("checkstyleNohttp").configure { + maxHeapSize = "1g" +} diff --git a/buildSrc/src/main/java/org/springframework/boot/build/MavenPublishingConventions.java b/buildSrc/src/main/java/org/springframework/boot/build/MavenPublishingConventions.java index c48d0a3cf7..711b733607 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/MavenPublishingConventions.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/MavenPublishingConventions.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,6 @@ import org.gradle.api.attributes.Usage; import org.gradle.api.component.AdhocComponentWithVariants; import org.gradle.api.component.ConfigurationVariantDetails; import org.gradle.api.plugins.JavaPlugin; -import org.gradle.api.plugins.JavaPluginConvention; import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.publish.PublishingExtension; import org.gradle.api.publish.VariantVersionMappingStrategy; @@ -115,9 +114,8 @@ class MavenPublishingConventions { */ private void addMavenOptionalFeature(Project project) { JavaPluginExtension extension = project.getExtensions().getByType(JavaPluginExtension.class); - JavaPluginConvention convention = project.getConvention().getPlugin(JavaPluginConvention.class); extension.registerFeature("mavenOptional", - (feature) -> feature.usingSourceSet(convention.getSourceSets().getByName("main"))); + (feature) -> feature.usingSourceSet(extension.getSourceSets().getByName("main"))); AdhocComponentWithVariants javaComponent = (AdhocComponentWithVariants) project.getComponents() .findByName("java"); javaComponent.addVariantsFromConfiguration( diff --git a/buildSrc/src/main/java/org/springframework/boot/build/autoconfigure/AutoConfigurationPlugin.java b/buildSrc/src/main/java/org/springframework/boot/build/autoconfigure/AutoConfigurationPlugin.java index c19f2fcffa..52e081d270 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/autoconfigure/AutoConfigurationPlugin.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/autoconfigure/AutoConfigurationPlugin.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; import org.gradle.api.plugins.JavaPlugin; -import org.gradle.api.plugins.JavaPluginConvention; +import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.tasks.SourceSet; import org.springframework.boot.build.DeployedPlugin; @@ -66,7 +66,7 @@ public class AutoConfigurationPlugin implements Plugin { .add(project.getDependencies().project(Collections.singletonMap("path", ":spring-boot-project:spring-boot-tools:spring-boot-configuration-processor"))); project.getTasks().create("autoConfigurationMetadata", AutoConfigurationMetadata.class, (task) -> { - SourceSet main = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets() + SourceSet main = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets() .getByName(SourceSet.MAIN_SOURCE_SET_NAME); task.setSourceSet(main); task.dependsOn(main.getClassesTaskName()); diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/BomPlugin.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/BomPlugin.java index 2426939385..2fc264df80 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/BomPlugin.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/BomPlugin.java @@ -21,8 +21,8 @@ import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; +import groovy.namespace.QName; import groovy.util.Node; -import groovy.xml.QName; import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; diff --git a/buildSrc/src/main/java/org/springframework/boot/build/context/properties/ConfigurationPropertiesPlugin.java b/buildSrc/src/main/java/org/springframework/boot/build/context/properties/ConfigurationPropertiesPlugin.java index 8229e5ddb4..2aed10187e 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/context/properties/ConfigurationPropertiesPlugin.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/context/properties/ConfigurationPropertiesPlugin.java @@ -16,9 +16,7 @@ package org.springframework.boot.build.context.properties; -import java.io.File; import java.util.Collections; -import java.util.concurrent.Callable; import java.util.stream.Collectors; import org.gradle.api.Plugin; @@ -27,7 +25,7 @@ import org.gradle.api.Task; import org.gradle.api.artifacts.Configuration; import org.gradle.api.file.RegularFile; import org.gradle.api.plugins.JavaPlugin; -import org.gradle.api.plugins.JavaPluginConvention; +import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.provider.Provider; import org.gradle.api.tasks.PathSensitivity; import org.gradle.api.tasks.SourceSet; @@ -94,20 +92,19 @@ public class ConfigurationPropertiesPlugin implements Plugin { } private void disableIncrementalCompilation(Project project) { - SourceSet mainSourceSet = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets() + SourceSet mainSourceSet = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets() .getByName(SourceSet.MAIN_SOURCE_SET_NAME); project.getTasks().named(mainSourceSet.getCompileJavaTaskName(), JavaCompile.class) .configure((compileJava) -> compileJava.getOptions().setIncremental(false)); } private void addMetadataArtifact(Project project) { - SourceSet mainSourceSet = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets() + SourceSet mainSourceSet = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets() .getByName(SourceSet.MAIN_SOURCE_SET_NAME); project.getConfigurations().maybeCreate(CONFIGURATION_PROPERTIES_METADATA_CONFIGURATION_NAME); project.afterEvaluate((evaluatedProject) -> evaluatedProject.getArtifacts().add( CONFIGURATION_PROPERTIES_METADATA_CONFIGURATION_NAME, - evaluatedProject.provider((Callable) () -> new File(mainSourceSet.getJava().getOutputDir(), - "META-INF/spring-configuration-metadata.json")), + mainSourceSet.getJava().getDestinationDirectory().dir("META-INF/spring-configuration-metadata.json"), (artifact) -> artifact .builtBy(evaluatedProject.getTasks().getByName(mainSourceSet.getClassesTaskName())))); } @@ -117,7 +114,7 @@ public class ConfigurationPropertiesPlugin implements Plugin { .getByName(JavaPlugin.COMPILE_JAVA_TASK_NAME); ((Task) compileJava).getInputs().files(project.getTasks().getByName(JavaPlugin.PROCESS_RESOURCES_TASK_NAME)) .withPathSensitivity(PathSensitivity.RELATIVE).withPropertyName("processed resources"); - SourceSet mainSourceSet = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets() + SourceSet mainSourceSet = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets() .getByName(SourceSet.MAIN_SOURCE_SET_NAME); compileJava.getOptions().getCompilerArgs() .add("-Aorg.springframework.boot.configurationprocessor.additionalMetadataLocations=" + StringUtils @@ -130,7 +127,7 @@ public class ConfigurationPropertiesPlugin implements Plugin { .register(CHECK_ADDITIONAL_SPRING_CONFIGURATION_METADATA_TASK_NAME, CheckAdditionalSpringConfigurationMetadata.class); checkConfigurationMetadata.configure((check) -> { - SourceSet mainSourceSet = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets() + SourceSet mainSourceSet = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets() .getByName(SourceSet.MAIN_SOURCE_SET_NAME); check.setSource(mainSourceSet.getResources()); check.include("META-INF/additional-spring-configuration-metadata.json"); @@ -145,7 +142,7 @@ public class ConfigurationPropertiesPlugin implements Plugin { TaskProvider checkConfigurationMetadata = project.getTasks() .register(CHECK_SPRING_CONFIGURATION_METADATA_TASK_NAME, CheckSpringConfigurationMetadata.class); checkConfigurationMetadata.configure((check) -> { - SourceSet mainSourceSet = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets() + SourceSet mainSourceSet = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets() .getByName(SourceSet.MAIN_SOURCE_SET_NAME); Provider metadataLocation = project.getTasks() .named(mainSourceSet.getCompileJavaTaskName(), JavaCompile.class) diff --git a/buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/MavenExec.java b/buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/MavenExec.java index cf84ec81ea..d3e9875f4d 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/MavenExec.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/MavenExec.java @@ -46,7 +46,7 @@ public class MavenExec extends JavaExec { public MavenExec() { setClasspath(mavenConfiguration(getProject())); args("--batch-mode"); - setMain("org.apache.maven.cli.MavenCli"); + getMainClass().set("org.apache.maven.cli.MavenCli"); } public void setProjectDir(File projectDir) { diff --git a/buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/MavenPluginPlugin.java b/buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/MavenPluginPlugin.java index ab9e10e2bf..f57c996e71 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/MavenPluginPlugin.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/MavenPluginPlugin.java @@ -64,7 +64,7 @@ import org.gradle.api.file.RegularFileProperty; import org.gradle.api.model.ObjectFactory; import org.gradle.api.plugins.JavaLibraryPlugin; import org.gradle.api.plugins.JavaPlugin; -import org.gradle.api.plugins.JavaPluginConvention; +import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.publish.PublishingExtension; import org.gradle.api.publish.maven.MavenPublication; import org.gradle.api.publish.maven.plugins.MavenPublishPlugin; @@ -225,7 +225,7 @@ public class MavenPluginPlugin implements Plugin { } private SourceSet getMainSourceSet(Project project) { - SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets(); + SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets(); return sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME); } diff --git a/buildSrc/src/main/java/org/springframework/boot/build/optional/OptionalDependenciesPlugin.java b/buildSrc/src/main/java/org/springframework/boot/build/optional/OptionalDependenciesPlugin.java index 90f2d79bf6..8b37308b15 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/optional/OptionalDependenciesPlugin.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/optional/OptionalDependenciesPlugin.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; import org.gradle.api.plugins.JavaPlugin; -import org.gradle.api.plugins.JavaPluginConvention; +import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.tasks.SourceSetContainer; /** @@ -44,7 +44,7 @@ public class OptionalDependenciesPlugin implements Plugin { optional.setCanBeConsumed(false); optional.setCanBeResolved(false); project.getPlugins().withType(JavaPlugin.class, (javaPlugin) -> { - SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class) + SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class) .getSourceSets(); sourceSets.all((sourceSet) -> { project.getConfigurations().getByName(sourceSet.getCompileClasspathConfigurationName()) diff --git a/buildSrc/src/main/java/org/springframework/boot/build/test/IntegrationTestPlugin.java b/buildSrc/src/main/java/org/springframework/boot/build/test/IntegrationTestPlugin.java index 66c7967629..29af0140d2 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/test/IntegrationTestPlugin.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/test/IntegrationTestPlugin.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ package org.springframework.boot.build.test; import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.plugins.JavaPlugin; -import org.gradle.api.plugins.JavaPluginConvention; +import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.SourceSetContainer; import org.gradle.api.tasks.testing.Test; @@ -61,7 +61,7 @@ public class IntegrationTestPlugin implements Plugin { } private SourceSet createSourceSet(Project project) { - SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets(); + SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets(); SourceSet intTestSourceSet = sourceSets.create(INT_TEST_SOURCE_SET_NAME); SourceSet main = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME); intTestSourceSet.setCompileClasspath(intTestSourceSet.getCompileClasspath().plus(main.getOutput())); diff --git a/buildSrc/src/main/java/org/springframework/boot/build/test/SystemTestPlugin.java b/buildSrc/src/main/java/org/springframework/boot/build/test/SystemTestPlugin.java index 634e110a69..242c4938ae 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/test/SystemTestPlugin.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/test/SystemTestPlugin.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.Task; import org.gradle.api.plugins.JavaPlugin; -import org.gradle.api.plugins.JavaPluginConvention; +import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.specs.Spec; import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.SourceSetContainer; @@ -65,7 +65,7 @@ public class SystemTestPlugin implements Plugin { } private SourceSet createSourceSet(Project project) { - SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets(); + SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets(); SourceSet systemTestSourceSet = sourceSets.create(SYSTEM_TEST_SOURCE_SET_NAME); SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME); systemTestSourceSet diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e708b1c023..249e5832f0 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ec991f9aa1..ae04661ee7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c787337..a69d9cb6c2 100755 --- a/gradlew +++ b/gradlew @@ -205,6 +205,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index 107acd32c4..f127cfd49d 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,7 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/ThreadDumpEndpointDocumentationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/ThreadDumpEndpointDocumentationTests.java index a64a99acba..53d85c503d 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/ThreadDumpEndpointDocumentationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/ThreadDumpEndpointDocumentationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -187,7 +187,10 @@ class ThreadDumpEndpointDocumentationTests extends MockMvcEndpointDocumentationT .andDo(MockMvcRestDocumentation.document("threaddump/text", preprocessResponse(new ContentModifyingOperationPreprocessor((bytes, mediaType) -> { String content = new String(bytes, StandardCharsets.UTF_8); - return content.substring(0, content.indexOf("\"main\" - Thread")).getBytes(); + int mainThreadIndex = content.indexOf("\"main\" - Thread"); + String truncatedContent = (mainThreadIndex >= 0) ? content.substring(0, mainThreadIndex) + : content; + return truncatedContent.getBytes(); })))); } diff --git a/spring-boot-project/spring-boot-parent/build.gradle b/spring-boot-project/spring-boot-parent/build.gradle index 8e68db4844..fa85a69df5 100644 --- a/spring-boot-project/spring-boot-parent/build.gradle +++ b/spring-boot-project/spring-boot-parent/build.gradle @@ -205,4 +205,9 @@ bom { dependencies { api(enforcedPlatform(project(":spring-boot-project:spring-boot-dependencies"))) -} \ No newline at end of file +} + +tasks.withType(GenerateModuleMetadata).configureEach { + // Internal module so enforced platform dependencies are OK + suppressedValidationErrors.add('enforced-platform') +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/dsl/SpringBootExtension.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/dsl/SpringBootExtension.java index fa37413be3..8bce3e9a3e 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/dsl/SpringBootExtension.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/dsl/SpringBootExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,9 +22,9 @@ import org.gradle.api.Action; import org.gradle.api.Project; import org.gradle.api.plugins.BasePlugin; import org.gradle.api.plugins.JavaPlugin; -import org.gradle.api.plugins.JavaPluginConvention; import org.gradle.api.provider.Property; import org.gradle.api.tasks.SourceSet; +import org.gradle.api.tasks.SourceSetContainer; import org.gradle.api.tasks.TaskContainer; import org.gradle.api.tasks.TaskProvider; import org.gradle.jvm.tasks.Jar; @@ -112,8 +112,12 @@ public class SpringBootExtension { } private File determineMainSourceSetResourcesOutputDir() { - return this.project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets() - .getByName(SourceSet.MAIN_SOURCE_SET_NAME).getOutput().getResourcesDir(); + return sourceSets(this.project).getByName(SourceSet.MAIN_SOURCE_SET_NAME).getOutput().getResourcesDir(); + } + + @SuppressWarnings("deprecation") + private SourceSetContainer sourceSets(Project project) { + return project.getConvention().getPlugin(org.gradle.api.plugins.JavaPluginConvention.class).getSourceSets(); } private String determineArtifactBaseName() { 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 dd5017a68a..84b2fe03d6 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 @@ -31,7 +31,7 @@ import org.gradle.api.distribution.DistributionContainer; import org.gradle.api.file.CopySpec; import org.gradle.api.file.FileCollection; import org.gradle.api.plugins.ApplicationPlugin; -import org.gradle.api.plugins.ApplicationPluginConvention; +import org.gradle.api.plugins.JavaApplication; import org.gradle.api.tasks.TaskProvider; import org.gradle.jvm.application.scripts.TemplateBasedScriptGenerator; import org.gradle.jvm.application.tasks.CreateStartScripts; @@ -45,21 +45,20 @@ final class ApplicationPluginAction implements PluginApplicationAction { @Override public void execute(Project project) { - ApplicationPluginConvention applicationConvention = project.getConvention() - .getPlugin(ApplicationPluginConvention.class); + JavaApplication javaApplication = project.getExtensions().getByType(JavaApplication.class); DistributionContainer distributions = project.getExtensions().getByType(DistributionContainer.class); Distribution distribution = distributions.create("boot"); distribution.getDistributionBaseName() - .convention((project.provider(() -> applicationConvention.getApplicationName() + "-boot"))); + .convention((project.provider(() -> javaApplication.getApplicationName() + "-boot"))); TaskProvider bootStartScripts = project.getTasks().register("bootStartScripts", CreateStartScripts.class, - (task) -> configureCreateStartScripts(project, applicationConvention, distribution, task)); + (task) -> configureCreateStartScripts(project, javaApplication, distribution, task)); CopySpec binCopySpec = project.copySpec().into("bin").from(bootStartScripts); binCopySpec.setFileMode(0755); distribution.getContents().with(binCopySpec); } - private void configureCreateStartScripts(Project project, ApplicationPluginConvention applicationConvention, + private void configureCreateStartScripts(Project project, JavaApplication javaApplication, Distribution distribution, CreateStartScripts createStartScripts) { createStartScripts .setDescription("Generates OS-specific start scripts to run the project as a Spring Boot application."); @@ -75,9 +74,8 @@ final class ApplicationPluginAction implements PluginApplicationAction { }); createStartScripts.getConventionMapping().map("outputDir", () -> new File(project.getBuildDir(), "bootScripts")); - createStartScripts.getConventionMapping().map("applicationName", applicationConvention::getApplicationName); - createStartScripts.getConventionMapping().map("defaultJvmOpts", - applicationConvention::getApplicationDefaultJvmArgs); + createStartScripts.getConventionMapping().map("applicationName", javaApplication::getApplicationName); + createStartScripts.getConventionMapping().map("defaultJvmOpts", javaApplication::getApplicationDefaultJvmArgs); } private CopySpec artifactFilesToLibCopySpec(Project project, Configuration configuration) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java index 593a568c1e..8935e4024e 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java @@ -36,7 +36,6 @@ import org.gradle.api.model.ObjectFactory; import org.gradle.api.plugins.ApplicationPlugin; import org.gradle.api.plugins.BasePlugin; import org.gradle.api.plugins.JavaPlugin; -import org.gradle.api.plugins.JavaPluginConvention; import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.provider.Provider; import org.gradle.api.tasks.SourceSet; @@ -98,8 +97,7 @@ final class JavaPluginAction implements PluginApplicationAction { } private TaskProvider configureBootJarTask(Project project) { - SourceSet mainSourceSet = javaPluginConvention(project).getSourceSets() - .getByName(SourceSet.MAIN_SOURCE_SET_NAME); + SourceSet mainSourceSet = sourceSets(project).getByName(SourceSet.MAIN_SOURCE_SET_NAME); Configuration developmentOnly = project.getConfigurations() .getByName(SpringBootPlugin.DEVELOPMENT_ONLY_CONFIGURATION_NAME); Configuration productionRuntimeClasspath = project.getConfigurations() @@ -125,8 +123,8 @@ final class JavaPluginAction implements PluginApplicationAction { buildImage.setDescription("Builds an OCI image of the application using the output of the bootJar task"); buildImage.setGroup(BasePlugin.BUILD_GROUP); buildImage.getArchiveFile().set(bootJar.get().getArchiveFile()); - buildImage.getTargetJavaVersion() - .set(project.provider(() -> javaPluginConvention(project).getTargetCompatibility())); + buildImage.getTargetJavaVersion().set(project.provider( + () -> project.getExtensions().getByType(JavaPluginExtension.class).getTargetCompatibility())); }); } @@ -135,8 +133,8 @@ final class JavaPluginAction implements PluginApplicationAction { } private void configureBootRunTask(Project project) { - Callable classpath = () -> javaPluginConvention(project).getSourceSets() - .findByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath().filter(new JarTypeFileSpec()); + Callable classpath = () -> sourceSets(project).findByName(SourceSet.MAIN_SOURCE_SET_NAME) + .getRuntimeClasspath().filter(new JarTypeFileSpec()); TaskProvider resolveProvider = ResolveMainClassName.registerForTask("bootRun", project, classpath); project.getTasks().register("bootRun", BootRun.class, (run) -> { @@ -160,8 +158,9 @@ final class JavaPluginAction implements PluginApplicationAction { run.getJavaLauncher().convention(toolchainService.launcherFor(toolchain)); } - private JavaPluginConvention javaPluginConvention(Project project) { - return project.getConvention().getPlugin(JavaPluginConvention.class); + @SuppressWarnings("deprecation") + private SourceSetContainer sourceSets(Project project) { + return project.getConvention().getPlugin(org.gradle.api.plugins.JavaPluginConvention.class).getSourceSets(); } private void configureUtf8Encoding(Project evaluatedProject) { @@ -189,9 +188,8 @@ final class JavaPluginAction implements PluginApplicationAction { } private void configureAdditionalMetadataLocations(JavaCompile compile) { - SourceSetContainer sourceSets = compile.getProject().getConvention().getPlugin(JavaPluginConvention.class) - .getSourceSets(); - sourceSets.stream().filter((candidate) -> candidate.getCompileJavaTaskName().equals(compile.getName())) + sourceSets(compile.getProject()).stream() + .filter((candidate) -> candidate.getCompileJavaTaskName().equals(compile.getName())) .map((match) -> match.getResources().getSrcDirs()).findFirst() .ifPresent((locations) -> compile.doFirst(new AdditionalMetadataLocationsConfigurer(locations))); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/MavenPluginAction.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/MavenPluginAction.java index 65772274e3..9a65640073 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/MavenPluginAction.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/MavenPluginAction.java @@ -17,10 +17,11 @@ package org.springframework.boot.gradle.plugin; import org.gradle.api.Action; +import org.gradle.api.GradleException; import org.gradle.api.Plugin; import org.gradle.api.Project; +import org.gradle.api.artifacts.repositories.ArtifactRepository; import org.gradle.api.publish.maven.plugins.MavenPublishPlugin; -import org.gradle.api.tasks.Upload; /** * {@link Action} that is executed in response to the @@ -46,7 +47,7 @@ final class MavenPluginAction implements PluginApplicationAction { @Override public void execute(Project project) { project.afterEvaluate((evaluated) -> { - project.getTasks().withType(Upload.class).configureEach((upload) -> { + project.getTasks().withType(org.gradle.api.tasks.Upload.class).configureEach((upload) -> { if (this.uploadTaskName.equals(upload.getName())) { clearConfigurationMappings(upload); } @@ -54,9 +55,28 @@ final class MavenPluginAction implements PluginApplicationAction { }); } - private void clearConfigurationMappings(Upload upload) { - upload.getRepositories().withType(org.gradle.api.artifacts.maven.MavenResolver.class, - (resolver) -> resolver.getPom().getScopeMappings().getMappings().clear()); + private void clearConfigurationMappings(org.gradle.api.tasks.Upload upload) { + upload.getRepositories().matching(this::isMavenResolver).all((resolver) -> { + try { + Object pom = resolver.getClass().getMethod("getPom").invoke(resolver); + Object scopeMappings = pom.getClass().getMethod("getScopeMappings").invoke(pom); + Object mappings = scopeMappings.getClass().getMethod("getMappings").invoke(scopeMappings); + mappings.getClass().getMethod("clear").invoke(mappings); + } + catch (Exception ex) { + throw new GradleException("Failed to clear configuration mappings for task '" + upload.getName() + "'", + ex); + } + }); + } + + private boolean isMavenResolver(ArtifactRepository repository) { + for (Class iface : repository.getClass().getInterfaces()) { + if ("org.gradle.api.artifacts.maven.GroovyMavenDeployer".equals(iface.getName())) { + return true; + } + } + return false; } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ResolveMainClassName.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ResolveMainClassName.java index edd8fa710e..86dbbd99c3 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ResolveMainClassName.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ResolveMainClassName.java @@ -34,7 +34,6 @@ import org.gradle.api.file.FileCollection; import org.gradle.api.file.RegularFile; import org.gradle.api.file.RegularFileProperty; import org.gradle.api.plugins.BasePlugin; -import org.gradle.api.plugins.Convention; import org.gradle.api.plugins.JavaApplication; import org.gradle.api.provider.Property; import org.gradle.api.provider.Provider; @@ -44,6 +43,7 @@ import org.gradle.api.tasks.Optional; import org.gradle.api.tasks.OutputFile; import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.TaskProvider; +import org.gradle.work.DisableCachingByDefault; import org.springframework.boot.gradle.dsl.SpringBootExtension; import org.springframework.boot.loader.tools.MainClassFinder; @@ -54,6 +54,7 @@ import org.springframework.boot.loader.tools.MainClassFinder; * @author Andy Wilkinson * @since 2.4 */ +@DisableCachingByDefault(because = "Not worth caching") public class ResolveMainClassName extends DefaultTask { private static final String SPRING_BOOT_APPLICATION_CLASS_NAME = "org.springframework.boot.autoconfigure.SpringBootApplication"; @@ -156,13 +157,12 @@ public class ResolveMainClassName extends DefaultTask { Callable classpath) { TaskProvider resolveMainClassNameProvider = project.getTasks() .register(taskName + "MainClassName", ResolveMainClassName.class, (resolveMainClassName) -> { - Convention convention = project.getConvention(); resolveMainClassName.setDescription( "Resolves the name of the application's main class for the " + taskName + " task."); resolveMainClassName.setGroup(BasePlugin.BUILD_GROUP); resolveMainClassName.setClasspath(classpath); resolveMainClassName.getConfiguredMainClassName().convention(project.provider(() -> { - String javaApplicationMainClass = getJavaApplicationMainClass(convention); + String javaApplicationMainClass = getJavaApplicationMainClass(project); if (javaApplicationMainClass != null) { return javaApplicationMainClass; } @@ -176,8 +176,8 @@ public class ResolveMainClassName extends DefaultTask { return resolveMainClassNameProvider; } - private static String getJavaApplicationMainClass(Convention convention) { - JavaApplication javaApplication = convention.findByType(JavaApplication.class); + private static String getJavaApplicationMainClass(Project project) { + JavaApplication javaApplication = project.getExtensions().findByType(JavaApplication.class); if (javaApplication == null) { return null; } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/WarPluginAction.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/WarPluginAction.java index 95184f8255..308ef31b8f 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/WarPluginAction.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/WarPluginAction.java @@ -72,10 +72,9 @@ class WarPluginAction implements PluginApplicationAction { .getByName(SpringBootPlugin.DEVELOPMENT_ONLY_CONFIGURATION_NAME); Configuration productionRuntimeClasspath = project.getConfigurations() .getByName(SpringBootPlugin.PRODUCTION_RUNTIME_CLASSPATH_CONFIGURATION_NAME); - Callable classpath = () -> project.getConvention().getByType(SourceSetContainer.class) - .getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath() - .minus(providedRuntimeConfiguration(project)).minus((developmentOnly.minus(productionRuntimeClasspath))) - .filter(new JarTypeFileSpec()); + Callable classpath = () -> sourceSets(project).getByName(SourceSet.MAIN_SOURCE_SET_NAME) + .getRuntimeClasspath().minus(providedRuntimeConfiguration(project)) + .minus((developmentOnly.minus(productionRuntimeClasspath))).filter(new JarTypeFileSpec()); TaskProvider resolveMainClassName = ResolveMainClassName .registerForTask(SpringBootPlugin.BOOT_WAR_TASK_NAME, project, classpath); TaskProvider bootWarProvider = project.getTasks().register(SpringBootPlugin.BOOT_WAR_TASK_NAME, @@ -95,6 +94,11 @@ class WarPluginAction implements PluginApplicationAction { return bootWarProvider; } + @SuppressWarnings("deprecation") + private SourceSetContainer sourceSets(Project project) { + return project.getConvention().getPlugin(org.gradle.api.plugins.JavaPluginConvention.class).getSourceSets(); + } + private FileCollection providedRuntimeConfiguration(Project project) { ConfigurationContainer configurations = project.getConfigurations(); return configurations.getByName(WarPlugin.PROVIDED_RUNTIME_CONFIGURATION_NAME); 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 4728caf87d..993937d7b0 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 @@ -30,6 +30,7 @@ import org.gradle.api.tasks.Nested; import org.gradle.api.tasks.OutputDirectory; import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.TaskExecutionException; +import org.gradle.work.DisableCachingByDefault; import org.springframework.boot.loader.tools.BuildPropertiesWriter; import org.springframework.boot.loader.tools.BuildPropertiesWriter.ProjectDetails; @@ -41,6 +42,7 @@ import org.springframework.boot.loader.tools.BuildPropertiesWriter.ProjectDetail * @author Andy Wilkinson * @since 2.0.0 */ +@DisableCachingByDefault(because = "Not worth caching") public class BuildInfo extends ConventionTask { private final BuildInfoProperties properties = new BuildInfoProperties(getProject()); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoProperties.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoProperties.java index d3a0bcedfb..1f25a56c55 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoProperties.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoProperties.java @@ -66,12 +66,17 @@ public class BuildInfoProperties implements Serializable { } private Provider projectVersion(Project project) { - Provider externalVersionProperty = project.getProviders().gradleProperty("version") - .forUseAtConfigurationTime(); + Provider externalVersionProperty = forUseAtConfigurationTime( + project.getProviders().gradleProperty("version")); externalVersionProperty.getOrNull(); return project.provider(() -> project.getVersion().toString()); } + @SuppressWarnings("deprecation") + private Provider forUseAtConfigurationTime(Provider provider) { + return provider.forUseAtConfigurationTime(); + } + /** * Returns the value used for the {@code build.group} property. Defaults to the * {@link Project#getGroup() Project's group}. diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImage.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImage.java index 46c9440b90..22acd8b05f 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImage.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImage.java @@ -36,7 +36,7 @@ import org.gradle.api.tasks.Nested; import org.gradle.api.tasks.Optional; import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.options.Option; -import org.gradle.util.ConfigureUtil; +import org.gradle.work.DisableCachingByDefault; import org.springframework.boot.buildpack.platform.build.BuildRequest; import org.springframework.boot.buildpack.platform.build.Builder; @@ -62,6 +62,7 @@ import org.springframework.util.StringUtils; * @author Julian Liebig * @since 2.3.0 */ +@DisableCachingByDefault public class BootBuildImage extends DefaultTask { private static final String BUILDPACK_JVM_VERSION_KEY = "BP_JVM_VERSION"; @@ -465,7 +466,7 @@ public class BootBuildImage extends DefaultTask { * @param closure the closure */ public void buildCache(Closure closure) { - buildCache(ConfigureUtil.configureUsing(closure)); + buildCache(Closures.asAction(closure)); } /** @@ -493,7 +494,7 @@ public class BootBuildImage extends DefaultTask { * @param closure the closure */ public void launchCache(Closure closure) { - launchCache(ConfigureUtil.configureUsing(closure)); + launchCache(Closures.asAction(closure)); } /** @@ -521,7 +522,7 @@ public class BootBuildImage extends DefaultTask { * @since 2.4.0 */ public void docker(Closure closure) { - docker(ConfigureUtil.configureUsing(closure)); + docker(Closures.asAction(closure)); } @TaskAction diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java index cf0aa0bf61..0c3b167541 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java @@ -34,6 +34,7 @@ import org.gradle.api.specs.Spec; import org.gradle.api.tasks.Internal; import org.gradle.api.tasks.Nested; import org.gradle.api.tasks.bundling.Jar; +import org.gradle.work.DisableCachingByDefault; /** * A custom {@link Jar} task that produces a Spring Boot executable jar. @@ -44,6 +45,7 @@ import org.gradle.api.tasks.bundling.Jar; * @author Phillip Webb * @since 2.0.0 */ +@DisableCachingByDefault(because = "Not worth caching") public class BootJar extends Jar implements BootArchive { private static final String LAUNCHER = "org.springframework.boot.loader.JarLauncher"; diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootWar.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootWar.java index 6d59f9d42f..0febf398f8 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootWar.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootWar.java @@ -35,6 +35,7 @@ import org.gradle.api.tasks.Internal; import org.gradle.api.tasks.Nested; import org.gradle.api.tasks.Optional; import org.gradle.api.tasks.bundling.War; +import org.gradle.work.DisableCachingByDefault; /** * A custom {@link War} task that produces a Spring Boot executable war. @@ -43,6 +44,7 @@ import org.gradle.api.tasks.bundling.War; * @author Phillip Webb * @since 2.0.0 */ +@DisableCachingByDefault(because = "Not worth caching") public class BootWar extends War implements BootArchive { private static final String LAUNCHER = "org.springframework.boot.loader.WarLauncher"; diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/CacheSpec.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/CacheSpec.java index 392cdd9212..df32a0e7cf 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/CacheSpec.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/CacheSpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2021 the original author or authors. + * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ import groovy.lang.Closure; import org.gradle.api.Action; import org.gradle.api.GradleException; import org.gradle.api.tasks.Input; -import org.gradle.util.ConfigureUtil; import org.springframework.boot.buildpack.platform.build.Cache; @@ -62,7 +61,7 @@ public class CacheSpec { if (this.cache != null) { throw new GradleException("Each image building cache can be configured only once"); } - volume(ConfigureUtil.configureUsing(closure)); + volume(Closures.asAction(closure)); } /** diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/Closures.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/Closures.java new file mode 100644 index 0000000000..eabe42f51b --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/Closures.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.gradle.tasks.bundling; + +import groovy.lang.Closure; +import org.gradle.api.Action; + +/** + * Wrapper for the deprecated {@link org.gradle.util.ConfigureUtil} that allows + * deprecation warnings to be suppressed in a single, focused location. + * + * @author Andy Wilkinson + */ +final class Closures { + + private Closures() { + + } + + @SuppressWarnings("deprecation") + static Action asAction(Closure closure) { + return org.gradle.util.ConfigureUtil.configureUsing(closure); + } + +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/DockerSpec.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/DockerSpec.java index 9308a4c3fe..687424f6d8 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/DockerSpec.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/DockerSpec.java @@ -22,7 +22,6 @@ import org.gradle.api.GradleException; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.Nested; import org.gradle.api.tasks.Optional; -import org.gradle.util.ConfigureUtil; import org.springframework.boot.buildpack.platform.docker.configuration.DockerConfiguration; @@ -110,7 +109,7 @@ public class DockerSpec { * @param closure the closure to apply */ public void builderRegistry(Closure closure) { - builderRegistry(ConfigureUtil.configureUsing(closure)); + builderRegistry(Closures.asAction(closure)); } /** @@ -138,7 +137,7 @@ public class DockerSpec { * @param closure the closure to apply */ public void publishRegistry(Closure closure) { - publishRegistry(ConfigureUtil.configureUsing(closure)); + publishRegistry(Closures.asAction(closure)); } /** diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/LayeredSpec.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/LayeredSpec.java index 4f60b88a06..d9e77e883a 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/LayeredSpec.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/LayeredSpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,6 @@ import groovy.lang.Closure; import org.gradle.api.Action; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.Optional; -import org.gradle.util.ConfigureUtil; import org.springframework.boot.loader.tools.Layer; import org.springframework.boot.loader.tools.Layers; @@ -133,7 +132,7 @@ public class LayeredSpec { * @param closure the closure */ public void application(Closure closure) { - application(ConfigureUtil.configureUsing(closure)); + application(Closures.asAction(closure)); } /** @@ -168,7 +167,7 @@ public class LayeredSpec { * @param closure the closure */ public void dependencies(Closure closure) { - dependencies(ConfigureUtil.configureUsing(closure)); + dependencies(Closures.asAction(closure)); } /** @@ -245,7 +244,7 @@ public class LayeredSpec { } public void intoLayer(String layer, Closure closure) { - intoLayer(layer, ConfigureUtil.configureUsing(closure)); + intoLayer(layer, Closures.asAction(closure)); } public void intoLayer(String layer, Action action) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/run/BootRun.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/run/BootRun.java index e08531c414..a0c46a4676 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/run/BootRun.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/run/BootRun.java @@ -27,6 +27,7 @@ import org.gradle.api.tasks.JavaExec; import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.SourceSetOutput; import org.gradle.jvm.toolchain.JavaLauncher; +import org.gradle.work.DisableCachingByDefault; /** * Custom {@link JavaExec} task for running a Spring Boot application. @@ -34,6 +35,7 @@ import org.gradle.jvm.toolchain.JavaLauncher; * @author Andy Wilkinson * @since 2.0.0 */ +@DisableCachingByDefault(because = "Application should always run") public class BootRun extends JavaExec { private boolean optimizedLaunch = true; diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleMultiDslExtension.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleMultiDslExtension.java index 9cebd90121..8171ff8e54 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleMultiDslExtension.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleMultiDslExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,7 +61,7 @@ public class GradleMultiDslExtension implements TestTemplateInvocationContextPro @Override public List getAdditionalExtensions() { GradleBuild gradleBuild = new GradleBuild(this.dsl); - gradleBuild.gradleVersion(GradleVersions.currentOrMinimumCompatible()); + gradleBuild.gradleVersion(GradleVersions.minimumCompatible()); return Arrays.asList(new GradleBuildFieldSetter(gradleBuild), new GradleBuildExtension()); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleProjectBuilder.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleProjectBuilder.java index 7042b97c2c..9f7a01053a 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleProjectBuilder.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleProjectBuilder.java @@ -68,7 +68,7 @@ public final class GradleProjectBuilder { builder.withName(this.name); } if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) { - NativeServices.initialize(userHome); + NativeServices.initializeOnClient(userHome); try { ProjectBuilderImpl.getGlobalServices(); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleVersions.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleVersions.java index 3d6320065c..4a8eeb4cac 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleVersions.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleVersions.java @@ -34,30 +34,24 @@ public final class GradleVersions { public static List allCompatible() { if (isJava18()) { - return Arrays.asList("7.3.3", "7.4.2", "7.5.1"); + return Arrays.asList("7.3.3", "7.4.2", GradleVersion.current().getVersion()); } if (isJava17()) { - return Arrays.asList("7.2", "7.3.3", "7.4.2", "7.5.1"); + return Arrays.asList("7.2", "7.3.3", "7.4.2", GradleVersion.current().getVersion()); } if (isJava16()) { - return Arrays.asList("7.0.2", "7.1", "7.2", "7.3.3", "7.4.2", "7.5.1"); + return Arrays.asList("7.0.2", "7.1", "7.2", "7.3.3", "7.4.2", GradleVersion.current().getVersion()); } - return Arrays.asList("6.8.3", GradleVersion.current().getVersion(), "7.0.2", "7.1.1", "7.2", "7.3.3", "7.4.2", - "7.5.1"); + return Arrays.asList("6.8.3", "6.9.2", "7.0.2", "7.1.1", "7.2", "7.3.3", "7.4.2", + GradleVersion.current().getVersion()); } - public static String currentOrMinimumCompatible() { - if (isJava17()) { - return "7.3.3"; - } - if (isJava16()) { - return "7.0.2"; - } - return GradleVersion.current().getVersion(); + public static String minimumCompatible() { + return allCompatible().get(0); } private static boolean isJava18() { - return JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_HIGHER); + return JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_18); } private static boolean isJava17() { diff --git a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/junit/GradleBuildInjectionExtension.java b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/junit/GradleBuildInjectionExtension.java index 4cafc9b3b0..e1f8086e92 100644 --- a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/junit/GradleBuildInjectionExtension.java +++ b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/junit/GradleBuildInjectionExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,7 @@ public class GradleBuildInjectionExtension implements BeforeEachCallback { GradleBuildInjectionExtension() { this.gradleBuild = new GradleBuild(); - this.gradleBuild.gradleVersion(GradleVersions.currentOrMinimumCompatible()); + this.gradleBuild.gradleVersion(GradleVersions.minimumCompatible()); String bootVersion = System.getProperty("springBootVersion"); Assert.notNull(bootVersion, "Property 'springBootVersion' must be set in build environment"); this.gradleBuild.bootVersion(bootVersion);