From 4f7e038f142f7c08e0a3c8c7a9221b27390d5296 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 1 Mar 2023 18:09:57 +0000 Subject: [PATCH] Test Gradle plugin against Gradle 8.0.1 Closes gh-34457 --- .../BootRunClasspathApplication.java | 3 +- .../JavaPluginActionIntegrationTests.java | 48 ++++++------------ .../bundling/BootJarIntegrationTests.java | 5 +- .../bundling/BootWarIntegrationTests.java | 27 +++++++++- .../tasks/run/BootRunIntegrationTests.java | 9 ++++ ...pplyingJavaPluginCreatesBootJarTask.gradle | 4 ++ ...pplyingJavaPluginCreatesBootRunTask.gradle | 4 ++ ...CreatesDevelopmentOnlyConfiguration.gradle | 12 +++++ ...elpfulWhenMainClassCannotBeResolved.gradle | 4 ++ ...errideDefaultParametersCompilerFlag.gradle | 13 +++-- ...arametersAndAdditionalCompilerFlags.gradle | 12 +++-- ...sUseParametersCompilerFlagByDefault.gradle | 12 +++-- ...sts-javaCompileTasksUseUtf8Encoding.gradle | 16 ++++++ ...BootJarTaskWithoutJavaPluginApplied.gradle | 3 ++ ...BootRunTaskWithoutJavaPluginApplied.gradle | 3 ++ ...ClasspathIsConfiguredWithAttributes.gradle | 16 ++++++ ...mabilityThatMatchesRuntimeClasspath.gradle | 19 +++++++ .../JavaPluginActionIntegrationTests.gradle | 49 ------------------- ...grationTests-buildsImageWithBinding.gradle | 2 +- ...ildsImageWithBuildpackFromDirectory.gradle | 2 +- ...buildsImageWithBuildpackFromTarGzip.gradle | 2 +- ...ionIsResolvedThenResolutionSucceeds.gradle | 10 ++-- ...pplicationPluginJvmArgumentsAreUsed.gradle | 4 +- ...nMainClassNameIsNotUsedWhenItIsNull.gradle | 6 --- .../gradle/testkit/GradleVersions.java | 8 +-- 25 files changed, 172 insertions(+), 121 deletions(-) create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-applyingJavaPluginCreatesBootJarTask.gradle create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-applyingJavaPluginCreatesBootRunTask.gradle create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-applyingJavaPluginCreatesDevelopmentOnlyConfiguration.gradle create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-errorMessageIsHelpfulWhenMainClassCannotBeResolved.gradle create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-javaCompileTasksUseUtf8Encoding.gradle create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-noBootJarTaskWithoutJavaPluginApplied.gradle create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-noBootRunTaskWithoutJavaPluginApplied.gradle create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-productionRuntimeClasspathIsConfiguredWithAttributes.gradle create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-productionRuntimeClasspathIsConfiguredWithResolvabilityAndConsumabilityThatMatchesRuntimeClasspath.gradle delete mode 100644 spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests.gradle diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/com/example/bootrun/classpath/BootRunClasspathApplication.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/com/example/bootrun/classpath/BootRunClasspathApplication.java index deaac0aafc43..8ad8995a108f 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/com/example/bootrun/classpath/BootRunClasspathApplication.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/com/example/bootrun/classpath/BootRunClasspathApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2023 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. @@ -31,6 +31,7 @@ protected BootRunClasspathApplication() { } public static void main(String[] args) { + System.out.println("Main class name = " + BootRunClasspathApplication.class.getName()); int i = 1; for (String entry : ManagementFactory.getRuntimeMXBean().getClassPath().split(File.pathSeparator)) { System.out.println(i++ + ". " + entry); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests.java index 551d9cd51c77..318c8528ac4b 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests.java @@ -47,53 +47,46 @@ class JavaPluginActionIntegrationTests { @TestTemplate void noBootJarTaskWithoutJavaPluginApplied() { - assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootJar").getOutput()) - .contains("bootJar exists = false"); + assertThat(this.gradleBuild.build("tasks").getOutput()).doesNotContain("bootJar"); } @TestTemplate void applyingJavaPluginCreatesBootJarTask() { - assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootJar", "-PapplyJavaPlugin").getOutput()) - .contains("bootJar exists = true"); + assertThat(this.gradleBuild.build("tasks").getOutput()).contains("bootJar"); } @TestTemplate void noBootRunTaskWithoutJavaPluginApplied() { - assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootRun").getOutput()) - .contains("bootRun exists = false"); + assertThat(this.gradleBuild.build("tasks").getOutput()).doesNotContain("bootRun"); } @TestTemplate void applyingJavaPluginCreatesBootRunTask() { - assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootRun", "-PapplyJavaPlugin").getOutput()) - .contains("bootRun exists = true"); + assertThat(this.gradleBuild.build("tasks").getOutput()).contains("bootRun"); } @TestTemplate void javaCompileTasksUseUtf8Encoding() { - assertThat(this.gradleBuild.build("javaCompileEncoding", "-PapplyJavaPlugin").getOutput()) - .contains("compileJava = UTF-8") + assertThat(this.gradleBuild.build("build").getOutput()).contains("compileJava = UTF-8") .contains("compileTestJava = UTF-8"); } @TestTemplate void javaCompileTasksUseParametersCompilerFlagByDefault() { - assertThat(this.gradleBuild.build("javaCompileTasksCompilerArgs").getOutput()) - .contains("compileJava compiler args: [-parameters]") + assertThat(this.gradleBuild.build("build").getOutput()).contains("compileJava compiler args: [-parameters]") .contains("compileTestJava compiler args: [-parameters]"); } @TestTemplate void javaCompileTasksUseParametersAndAdditionalCompilerFlags() { - assertThat(this.gradleBuild.build("javaCompileTasksCompilerArgs").getOutput()) + assertThat(this.gradleBuild.build("build").getOutput()) .contains("compileJava compiler args: [-parameters, -Xlint:all]") .contains("compileTestJava compiler args: [-parameters, -Xlint:all]"); } @TestTemplate void javaCompileTasksCanOverrideDefaultParametersCompilerFlag() { - assertThat(this.gradleBuild.build("javaCompileTasksCompilerArgs").getOutput()) - .contains("compileJava compiler args: [-Xlint:all]") + assertThat(this.gradleBuild.build("build").getOutput()).contains("compileJava compiler args: [-Xlint:all]") .contains("compileTestJava compiler args: [-Xlint:all]"); } @@ -139,16 +132,12 @@ void additionalMetadataLocationsNotConfiguredWhenProcessorIsAbsent() throws IOEx @TestTemplate void applyingJavaPluginCreatesDevelopmentOnlyConfiguration() { - assertThat(this.gradleBuild - .build("configurationExists", "-PconfigurationName=developmentOnly", "-PapplyJavaPlugin") - .getOutput()).contains("developmentOnly exists = true"); + assertThat(this.gradleBuild.build("build").getOutput()).contains("developmentOnly exists = true"); } @TestTemplate void productionRuntimeClasspathIsConfiguredWithAttributes() { - assertThat(this.gradleBuild - .build("configurationAttributes", "-PconfigurationName=productionRuntimeClasspath", "-PapplyJavaPlugin") - .getOutput()).contains("3 productionRuntimeClasspath attributes:") + assertThat(this.gradleBuild.build("build").getOutput()).contains("3 productionRuntimeClasspath attributes:") .contains("org.gradle.usage: java-runtime") .contains("org.gradle.libraryelements: jar") .contains("org.gradle.dependency.bundling: external"); @@ -156,18 +145,11 @@ void productionRuntimeClasspathIsConfiguredWithAttributes() { @TestTemplate void productionRuntimeClasspathIsConfiguredWithResolvabilityAndConsumabilityThatMatchesRuntimeClasspath() { - String runtime = this.gradleBuild - .build("configurationResolvabilityAndConsumability", "-PconfigurationName=runtimeClasspath", - "-PapplyJavaPlugin") - .getOutput(); - assertThat(runtime).contains("canBeResolved: true"); - assertThat(runtime).contains("canBeConsumed: false"); - String productionRuntime = this.gradleBuild - .build("configurationResolvabilityAndConsumability", "-PconfigurationName=productionRuntimeClasspath", - "-PapplyJavaPlugin") - .getOutput(); - assertThat(productionRuntime).contains("canBeResolved: true"); - assertThat(productionRuntime).contains("canBeConsumed: false"); + String output = this.gradleBuild.build("build").getOutput(); + assertThat(output).contains("runtimeClasspath canBeResolved: true"); + assertThat(output).contains("runtimeClasspath canBeConsumed: false"); + assertThat(output).contains("productionRuntimeClasspath canBeResolved: true"); + assertThat(output).contains("productionRuntimeClasspath canBeConsumed: false"); } @TestTemplate diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests.java index 3657a86ad80f..146fb595ae60 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests.java @@ -22,7 +22,6 @@ import java.util.TreeSet; import org.gradle.testkit.runner.BuildResult; -import org.gradle.testkit.runner.TaskOutcome; import org.junit.jupiter.api.TestTemplate; import org.springframework.boot.gradle.junit.GradleCompatibility; @@ -45,9 +44,7 @@ class BootJarIntegrationTests extends AbstractBootArchiveIntegrationTests { @TestTemplate void whenAResolvableCopyOfAnUnresolvableConfigurationIsResolvedThenResolutionSucceeds() { - BuildResult build = this.gradleBuild.build("resolveResolvableCopyOfUnresolvableConfiguration"); - assertThat(build.task(":resolveResolvableCopyOfUnresolvableConfiguration").getOutcome()) - .isEqualTo(TaskOutcome.SUCCESS); + this.gradleBuild.expectDeprecationWarningsWithAtLeastVersion("8.0").build("build"); } @TestTemplate diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootWarIntegrationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootWarIntegrationTests.java index fe609b26b0b5..4fa39536edac 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootWarIntegrationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootWarIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2023 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. @@ -16,10 +16,14 @@ package org.springframework.boot.gradle.tasks.bundling; +import java.io.IOException; import java.util.Arrays; import java.util.Set; import java.util.TreeSet; +import org.assertj.core.api.Assumptions; +import org.gradle.util.GradleVersion; + import org.springframework.boot.gradle.junit.GradleCompatibility; /** @@ -42,4 +46,25 @@ String[] getExpectedApplicationLayerContents(String... additionalFiles) { return contents.toArray(new String[0]); } + @Override + void multiModuleImplicitLayers() throws IOException { + whenTestingWithTheConfigurationCacheAssumeThatTheGradleVersionIsLessThan8(); + super.multiModuleImplicitLayers(); + } + + @Override + void multiModuleCustomLayers() throws IOException { + whenTestingWithTheConfigurationCacheAssumeThatTheGradleVersionIsLessThan8(); + super.multiModuleCustomLayers(); + } + + private void whenTestingWithTheConfigurationCacheAssumeThatTheGradleVersionIsLessThan8() { + if (this.gradleBuild.isConfigurationCache()) { + // With Gradle 8.0, a configuration cache bug prevents ResolvedDependencies + // from processing dependencies on the runtime classpath + Assumptions.assumeThat(GradleVersion.version(this.gradleBuild.getGradleVersion())) + .isLessThan(GradleVersion.version("8.0")); + } + } + } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/run/BootRunIntegrationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/run/BootRunIntegrationTests.java index d8b5d225644d..fb4f4cf0e030 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/run/BootRunIntegrationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/run/BootRunIntegrationTests.java @@ -24,9 +24,11 @@ import java.util.jar.JarOutputStream; import java.util.jar.Manifest; +import org.assertj.core.api.Assumptions; import org.gradle.api.JavaVersion; import org.gradle.testkit.runner.BuildResult; import org.gradle.testkit.runner.TaskOutcome; +import org.gradle.util.GradleVersion; import org.junit.jupiter.api.TestTemplate; import org.springframework.boot.gradle.junit.GradleCompatibility; @@ -114,6 +116,13 @@ void optimizedLaunchDisabledJvmArgs() throws IOException { @TestTemplate void applicationPluginJvmArgumentsAreUsed() throws IOException { + if (this.gradleBuild.isConfigurationCache()) { + // https://github.com/gradle/gradle/pull/23924 + GradleVersion gradleVersion = GradleVersion.version(this.gradleBuild.getGradleVersion()); + Assumptions.assumeThat(gradleVersion) + .isLessThan(GradleVersion.version("8.0")) + .isGreaterThanOrEqualTo(GradleVersion.version("8.1-rc-1")); + } copyJvmArgsApplication(); BuildResult result = this.gradleBuild.build("bootRun"); assertThat(result.task(":bootRun").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-applyingJavaPluginCreatesBootJarTask.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-applyingJavaPluginCreatesBootJarTask.gradle new file mode 100644 index 000000000000..b1e3f5f69194 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-applyingJavaPluginCreatesBootJarTask.gradle @@ -0,0 +1,4 @@ +plugins { + id 'org.springframework.boot' version '{version}' + id 'java' +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-applyingJavaPluginCreatesBootRunTask.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-applyingJavaPluginCreatesBootRunTask.gradle new file mode 100644 index 000000000000..b1e3f5f69194 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-applyingJavaPluginCreatesBootRunTask.gradle @@ -0,0 +1,4 @@ +plugins { + id 'org.springframework.boot' version '{version}' + id 'java' +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-applyingJavaPluginCreatesDevelopmentOnlyConfiguration.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-applyingJavaPluginCreatesDevelopmentOnlyConfiguration.gradle new file mode 100644 index 000000000000..59e54b136815 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-applyingJavaPluginCreatesDevelopmentOnlyConfiguration.gradle @@ -0,0 +1,12 @@ +plugins { + id 'org.springframework.boot' version '{version}' + id 'java' +} + +springBoot { + mainClass = "com.example.Main" +} + +gradle.taskGraph.whenReady { + println "developmentOnly exists = ${configurations.findByName('developmentOnly') != null}" +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-errorMessageIsHelpfulWhenMainClassCannotBeResolved.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-errorMessageIsHelpfulWhenMainClassCannotBeResolved.gradle new file mode 100644 index 000000000000..b1e3f5f69194 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-errorMessageIsHelpfulWhenMainClassCannotBeResolved.gradle @@ -0,0 +1,4 @@ +plugins { + id 'org.springframework.boot' version '{version}' + id 'java' +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-javaCompileTasksCanOverrideDefaultParametersCompilerFlag.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-javaCompileTasksCanOverrideDefaultParametersCompilerFlag.gradle index 0d4893bca274..ef76cc81c83b 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-javaCompileTasksCanOverrideDefaultParametersCompilerFlag.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-javaCompileTasksCanOverrideDefaultParametersCompilerFlag.gradle @@ -3,15 +3,18 @@ plugins { id 'org.springframework.boot' version '{version}' } +springBoot { + mainClass = "com.example.Main" +} + tasks.withType(JavaCompile) { options.compilerArgs = ['-Xlint:all'] } - -task('javaCompileTasksCompilerArgs') { - doFirst { - tasks.withType(JavaCompile) { - println "${name} compiler args: ${options.compilerArgs}" +gradle.taskGraph.whenReady { + gradle.taskGraph.allTasks.each { + if (it instanceof JavaCompile) { + println "${it.name} compiler args: ${it.options.compilerArgs}" } } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-javaCompileTasksUseParametersAndAdditionalCompilerFlags.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-javaCompileTasksUseParametersAndAdditionalCompilerFlags.gradle index f018b3a2a491..708bc26560e5 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-javaCompileTasksUseParametersAndAdditionalCompilerFlags.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-javaCompileTasksUseParametersAndAdditionalCompilerFlags.gradle @@ -3,14 +3,18 @@ plugins { id 'org.springframework.boot' version '{version}' } +springBoot { + mainClass = "com.example.Main" +} + tasks.withType(JavaCompile) { options.compilerArgs << '-Xlint:all' } -task('javaCompileTasksCompilerArgs') { - doFirst { - tasks.withType(JavaCompile) { - println "${name} compiler args: ${options.compilerArgs}" +gradle.taskGraph.whenReady { + gradle.taskGraph.allTasks.each { + if (it instanceof JavaCompile) { + println "${it.name} compiler args: ${it.options.compilerArgs}" } } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-javaCompileTasksUseParametersCompilerFlagByDefault.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-javaCompileTasksUseParametersCompilerFlagByDefault.gradle index ed3eb61ff925..2627c5486bd0 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-javaCompileTasksUseParametersCompilerFlagByDefault.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-javaCompileTasksUseParametersCompilerFlagByDefault.gradle @@ -3,10 +3,14 @@ plugins { id 'org.springframework.boot' version '{version}' } -task('javaCompileTasksCompilerArgs') { - doFirst { - tasks.withType(JavaCompile) { - println "${name} compiler args: ${options.compilerArgs}" +springBoot { + mainClass = "com.example.Main" +} + +gradle.taskGraph.whenReady { + gradle.taskGraph.allTasks.each { + if (it instanceof JavaCompile) { + println "${it.name} compiler args: ${it.options.compilerArgs}" } } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-javaCompileTasksUseUtf8Encoding.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-javaCompileTasksUseUtf8Encoding.gradle new file mode 100644 index 000000000000..c1a3e0f92b45 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-javaCompileTasksUseUtf8Encoding.gradle @@ -0,0 +1,16 @@ +plugins { + id 'org.springframework.boot' version '{version}' + id 'java' +} + +springBoot { + mainClass = "com.example.Main" +} + +gradle.taskGraph.whenReady { + gradle.taskGraph.allTasks.each { + if (it instanceof JavaCompile) { + println "${it.name} = ${it.options.encoding}" + } + } +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-noBootJarTaskWithoutJavaPluginApplied.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-noBootJarTaskWithoutJavaPluginApplied.gradle new file mode 100644 index 000000000000..cf13509ffddd --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-noBootJarTaskWithoutJavaPluginApplied.gradle @@ -0,0 +1,3 @@ +plugins { + id 'org.springframework.boot' version '{version}' +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-noBootRunTaskWithoutJavaPluginApplied.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-noBootRunTaskWithoutJavaPluginApplied.gradle new file mode 100644 index 000000000000..cf13509ffddd --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-noBootRunTaskWithoutJavaPluginApplied.gradle @@ -0,0 +1,3 @@ +plugins { + id 'org.springframework.boot' version '{version}' +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-productionRuntimeClasspathIsConfiguredWithAttributes.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-productionRuntimeClasspathIsConfiguredWithAttributes.gradle new file mode 100644 index 000000000000..c4ccd15df3ab --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-productionRuntimeClasspathIsConfiguredWithAttributes.gradle @@ -0,0 +1,16 @@ +plugins { + id 'org.springframework.boot' version '{version}' + id 'java' +} + +springBoot { + mainClass = "com.example.Main" +} + +gradle.taskGraph.whenReady { + def attributes = configurations.findByName('productionRuntimeClasspath').attributes + println "${attributes.keySet().size()} productionRuntimeClasspath attributes:" + attributes.keySet().each { attribute -> + println " ${attribute}: ${attributes.getAttribute(attribute)}" + } +} \ No newline at end of file diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-productionRuntimeClasspathIsConfiguredWithResolvabilityAndConsumabilityThatMatchesRuntimeClasspath.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-productionRuntimeClasspathIsConfiguredWithResolvabilityAndConsumabilityThatMatchesRuntimeClasspath.gradle new file mode 100644 index 000000000000..c4e5cf27057f --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests-productionRuntimeClasspathIsConfiguredWithResolvabilityAndConsumabilityThatMatchesRuntimeClasspath.gradle @@ -0,0 +1,19 @@ +plugins { + id 'org.springframework.boot' version '{version}' + id 'java' +} + +springBoot { + mainClass = "com.example.Main" +} + +gradle.taskGraph.whenReady { + analyzeConfiguration('productionRuntimeClasspath') + analyzeConfiguration('runtimeClasspath') +} + +def analyzeConfiguration(String configurationName) { + Configuration configuration = configurations.findByName(configurationName) + println "$configurationName canBeResolved: ${configuration.canBeResolved}" + println "$configurationName canBeConsumed: ${configuration.canBeConsumed}" +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests.gradle deleted file mode 100644 index e96ca9aa2819..000000000000 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests.gradle +++ /dev/null @@ -1,49 +0,0 @@ -plugins { - id 'org.springframework.boot' version '{version}' -} - -if (project.hasProperty('applyJavaPlugin')) { - apply plugin: 'java' -} - -task('taskExists') { - doFirst { - println "${taskName} exists = ${tasks.findByName(taskName) != null}" - } -} - -task('javaCompileEncoding') { - doFirst { - tasks.withType(JavaCompile) { - println "${name} = ${options.encoding}" - } - } -} - -task('configurationExists') { - doFirst { - println "${configurationName} exists = ${configurations.findByName(configurationName) != null}" - } -} - -task('configurationAttributes') { - doFirst { - def attributes = configurations.findByName(configurationName).attributes - println "${attributes.keySet().size()} ${configurationName} attributes:" - attributes.keySet().each { attribute -> - println " ${attribute}: ${attributes.getAttribute(attribute)}" - } - } -} - -task('configurationResolvabilityAndConsumability') { - if (project.hasProperty("configurationName")) { - Configuration configuration = configurations.findByName(configurationName) - def canBeResolved = configuration.canBeResolved - def canBeConsumed = configuration.canBeConsumed - doFirst { - println "canBeResolved: ${canBeResolved}" - println "canBeConsumed: ${canBeConsumed}" - } - } -} \ No newline at end of file diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests-buildsImageWithBinding.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests-buildsImageWithBinding.gradle index d9cb8f4b43a6..bc303f1033ba 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests-buildsImageWithBinding.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests-buildsImageWithBinding.gradle @@ -8,5 +8,5 @@ targetCompatibility = '1.8' bootBuildImage { builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1" - bindings = [ "${projectDir}/bindings/ca-certificates:/platform/bindings/certificates" ] + bindings = [ "${projectDir}/bindings/ca-certificates:/platform/bindings/certificates" as String ] } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests-buildsImageWithBuildpackFromDirectory.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests-buildsImageWithBuildpackFromDirectory.gradle index b21045dce189..ea724f8900a1 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests-buildsImageWithBuildpackFromDirectory.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests-buildsImageWithBuildpackFromDirectory.gradle @@ -8,5 +8,5 @@ targetCompatibility = '1.8' bootBuildImage { builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1" - buildpacks = [ "file://${projectDir}/buildpack/hello-world" ] + buildpacks = [ "file://${projectDir}/buildpack/hello-world" as String ] } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests-buildsImageWithBuildpackFromTarGzip.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests-buildsImageWithBuildpackFromTarGzip.gradle index 4f3a7b94748f..1f8d022ea565 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests-buildsImageWithBuildpackFromTarGzip.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests-buildsImageWithBuildpackFromTarGzip.gradle @@ -8,5 +8,5 @@ targetCompatibility = '1.8' bootBuildImage { builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1" - buildpacks = [ "file://${projectDir}/hello-world.tgz" ] + buildpacks = [ "file://${projectDir}/hello-world.tgz" as String ] } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-whenAResolvableCopyOfAnUnresolvableConfigurationIsResolvedThenResolutionSucceeds.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-whenAResolvableCopyOfAnUnresolvableConfigurationIsResolvedThenResolutionSucceeds.gradle index 2f5e2250a89c..21015b745930 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-whenAResolvableCopyOfAnUnresolvableConfigurationIsResolvedThenResolutionSucceeds.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-whenAResolvableCopyOfAnUnresolvableConfigurationIsResolvedThenResolutionSucceeds.gradle @@ -7,10 +7,8 @@ bootJar { mainClass = 'com.example.Application' } -task resolveResolvableCopyOfUnresolvableConfiguration { - doFirst { - def copy = configurations.implementation.copyRecursive() - copy.canBeResolved = true - copy.resolve() - } +gradle.taskGraph.whenReady { + def copy = configurations.implementation.copyRecursive() + copy.canBeResolved = true + copy.resolve() } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/run/BootRunIntegrationTests-applicationPluginJvmArgumentsAreUsed.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/run/BootRunIntegrationTests-applicationPluginJvmArgumentsAreUsed.gradle index 9db3ab19b05e..6e85f01a8616 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/run/BootRunIntegrationTests-applicationPluginJvmArgumentsAreUsed.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/run/BootRunIntegrationTests-applicationPluginJvmArgumentsAreUsed.gradle @@ -3,4 +3,6 @@ plugins { id 'org.springframework.boot' version '{version}' } -applicationDefaultJvmArgs = ['-Dcom.foo=bar', '-Dcom.bar=baz'] +application { + applicationDefaultJvmArgs = ['-Dcom.foo=bar', '-Dcom.bar=baz'] +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/run/BootRunIntegrationTests-applicationPluginMainClassNameIsNotUsedWhenItIsNull.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/run/BootRunIntegrationTests-applicationPluginMainClassNameIsNotUsedWhenItIsNull.gradle index 5e803a3fc5d5..e351e2cbb941 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/run/BootRunIntegrationTests-applicationPluginMainClassNameIsNotUsedWhenItIsNull.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/run/BootRunIntegrationTests-applicationPluginMainClassNameIsNotUsedWhenItIsNull.gradle @@ -2,9 +2,3 @@ plugins { id 'application' id 'org.springframework.boot' version '{version}' } - -bootRun { - doFirst { - println "Main class name = ${bootRun.mainClass.get()}" - } -} \ No newline at end of file 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 580b4f15f22f..15a19d813da3 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,15 +34,15 @@ private GradleVersions() { public static List allCompatible() { if (isJava18()) { - return Arrays.asList("7.3.3", GradleVersion.current().getVersion()); + return Arrays.asList("7.3.3", GradleVersion.current().getVersion(), "8.0.1"); } if (isJava17()) { - return Arrays.asList("7.2", GradleVersion.current().getVersion()); + return Arrays.asList("7.2", GradleVersion.current().getVersion(), "8.0.1"); } if (isJava16()) { - return Arrays.asList("7.0.2", GradleVersion.current().getVersion()); + return Arrays.asList("7.0.2", GradleVersion.current().getVersion(), "8.0.1"); } - return Arrays.asList("6.8.3", "6.9.4", "7.0.2", GradleVersion.current().getVersion()); + return Arrays.asList("6.8.3", "6.9.4", "7.0.2", GradleVersion.current().getVersion(), "8.0.1"); } public static String minimumCompatible() {