Raise the minimum supported version of Gradle to 5.6

Closes gh-18777
This commit is contained in:
Andy Wilkinson
2020-01-13 12:09:21 +00:00
parent 3bd9eea079
commit e415f759a2
12 changed files with 28 additions and 98 deletions

View File

@@ -38,7 +38,7 @@ Andy Wilkinson
The Spring Boot Gradle Plugin provides Spring Boot support in https://gradle.org[Gradle].
It allows you to package executable jar or war archives, run Spring Boot applications, and use the dependency management provided by `spring-boot-dependencies`.
Spring Boot's Gradle plugin requires Gradle 5.x or 6.x (4.10 is also supported but this support is deprecated and will be removed in a future release).
Spring Boot's Gradle plugin requires Gradle 6.x (5.6 is also supported but this support is deprecated and will be removed in a future release).
In addition to this user guide, {api-documentation}[API documentation] is also available.

View File

@@ -17,16 +17,13 @@
package org.springframework.boot.gradle.dsl;
import java.io.File;
import java.lang.reflect.Method;
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.bundling.AbstractArchiveTask;
import org.gradle.jvm.tasks.Jar;
import org.springframework.boot.gradle.tasks.buildinfo.BuildInfo;
@@ -118,7 +115,7 @@ public class SpringBootExtension {
private String determineArtifactBaseName() {
Jar artifactTask = findArtifactTask();
return (artifactTask != null) ? getArchiveBaseName(artifactTask) : null;
return (artifactTask != null) ? artifactTask.getArchiveBaseName().get() : null;
}
private Jar findArtifactTask() {
@@ -129,27 +126,4 @@ public class SpringBootExtension {
return (Jar) this.project.getTasks().findByName("bootJar");
}
@SuppressWarnings("unchecked")
private static String getArchiveBaseName(AbstractArchiveTask task) {
try {
Method method = findMethod(task.getClass(), "getArchiveBaseName");
if (method != null) {
return ((Property<String>) method.invoke(task)).get();
}
}
catch (Exception ex) {
// Continue
}
return task.getBaseName();
}
private static Method findMethod(Class<?> type, String name) {
for (Method candidate : type.getMethods()) {
if (candidate.getName().equals(name)) {
return candidate;
}
}
return null;
}
}

View File

@@ -85,8 +85,8 @@ public class SpringBootPlugin implements Plugin<Project> {
}
private void verifyGradleVersion() {
if (GradleVersion.current().compareTo(GradleVersion.version("4.10")) < 0) {
throw new GradleException("Spring Boot plugin requires Gradle 4.10 or later. The current version is "
if (GradleVersion.current().compareTo(GradleVersion.version("5.6")) < 0) {
throw new GradleException("Spring Boot plugin requires Gradle 5.6 or later. The current version is "
+ GradleVersion.current());
}
}

View File

@@ -20,7 +20,6 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
@@ -38,7 +37,6 @@ import org.gradle.api.java.archives.Attributes;
import org.gradle.api.specs.Spec;
import org.gradle.api.specs.Specs;
import org.gradle.api.tasks.WorkResult;
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
import org.gradle.api.tasks.bundling.Jar;
import org.gradle.api.tasks.util.PatternSet;
@@ -95,37 +93,16 @@ class BootArchiveSupport {
}
CopyAction createCopyAction(Jar jar) {
CopyAction copyAction = new BootZipCopyAction(getOutputLocation(jar), jar.isPreserveFileTimestamps(),
isUsingDefaultLoader(jar), this.requiresUnpack.getAsSpec(), this.exclusions.getAsExcludeSpec(),
this.launchScript, this.compressionResolver, jar.getMetadataCharset());
CopyAction copyAction = new BootZipCopyAction(jar.getArchiveFile().get().getAsFile(),
jar.isPreserveFileTimestamps(), isUsingDefaultLoader(jar), this.requiresUnpack.getAsSpec(),
this.exclusions.getAsExcludeSpec(), this.launchScript, this.compressionResolver,
jar.getMetadataCharset());
if (!jar.isReproducibleFileOrder()) {
return copyAction;
}
return new ReproducibleOrderingCopyAction(copyAction);
}
private static File getOutputLocation(AbstractArchiveTask task) {
try {
Method method = findMethod(task.getClass(), "getArchiveFile");
if (method != null) {
return (File) method.invoke(task);
}
}
catch (Exception ex) {
// Continue
}
return task.getArchivePath();
}
private static Method findMethod(Class<?> type, String name) {
for (Method candidate : type.getMethods()) {
if (candidate.getName().equals(name)) {
return candidate;
}
}
return null;
}
private boolean isUsingDefaultLoader(Jar jar) {
return DEFAULT_LAUNCHER_CLASSES.contains(jar.getManifest().getAttributes().get("Main-Class"));
}

View File

@@ -19,13 +19,11 @@ package org.springframework.boot.gradle.tasks.bundling;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
import org.gradle.api.Project;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
import org.springframework.boot.loader.tools.FileUtils;
@@ -52,35 +50,12 @@ public class LaunchScriptConfiguration implements Serializable {
LaunchScriptConfiguration(AbstractArchiveTask archiveTask) {
Project project = archiveTask.getProject();
String baseName = getArchiveBaseName(archiveTask);
String baseName = archiveTask.getArchiveBaseName().get();
putIfMissing(this.properties, "initInfoProvides", baseName);
putIfMissing(this.properties, "initInfoShortDescription", removeLineBreaks(project.getDescription()), baseName);
putIfMissing(this.properties, "initInfoDescription", augmentLineBreaks(project.getDescription()), baseName);
}
@SuppressWarnings("unchecked")
private static String getArchiveBaseName(AbstractArchiveTask task) {
try {
Method method = findMethod(task.getClass(), "getArchiveBaseName");
if (method != null) {
return ((Property<String>) method.invoke(task)).get();
}
}
catch (Exception ex) {
// Continue
}
return task.getBaseName();
}
private static Method findMethod(Class<?> type, String name) {
for (Method candidate : type.getMethods()) {
if (candidate.getName().equals(name)) {
return candidate;
}
}
return null;
}
/**
* Returns the properties that are applied to the launch script when it's being
* including in the executable archive.

View File

@@ -43,9 +43,9 @@ class RunningDocumentationTests {
@TestTemplate
@DisabledOnJre(JRE.JAVA_13)
void bootRunMain() throws IOException {
// TODO Testing of convention mappings is flakey in 5.2+
// Testing of convention mappings is flakey between 5.2 and 6.0 inclusive
// https://github.com/gradle/gradle/issues/11323
assertThat(this.gradleBuild.gradleVersion("5.1.1").script("src/docs/gradle/running/boot-run-main")
assertThat(this.gradleBuild.gradleVersion("6.1-rc-2").script("src/docs/gradle/running/boot-run-main")
.build("configuredMainClass").getOutput()).contains("com.example.ExampleApplication");
}

View File

@@ -47,8 +47,7 @@ public final class GradleCompatibilityExtension implements TestTemplateInvocatio
GRADLE_VERSIONS = Collections.singletonList("default");
}
else {
GRADLE_VERSIONS = Arrays.asList("4.10.3", "5.0", "5.1.1", "5.2.1", "5.3.1", "5.4.1", "5.5.1", "5.6.4",
"default");
GRADLE_VERSIONS = Arrays.asList("5.6.4", "default");
}
}

View File

@@ -40,19 +40,19 @@ class SpringBootPluginIntegrationTests {
@Test
void failFastWithVersionOfGradleLowerThanRequired() {
BuildResult result = this.gradleBuild.gradleVersion("4.9").buildAndFail();
BuildResult result = this.gradleBuild.gradleVersion("5.5.1").buildAndFail();
assertThat(result.getOutput())
.contains("Spring Boot plugin requires Gradle 4.10 or later. The current version is Gradle 4.9");
.contains("Spring Boot plugin requires Gradle 5.6 or later. The current version is Gradle 5.5.1");
}
@Test
void succeedWithVersionOfGradleHigherThanRequired() {
this.gradleBuild.gradleVersion("4.10.1").build();
this.gradleBuild.gradleVersion("5.6.1").build();
}
@Test
void succeedWithVersionOfGradleMatchingWhatIsRequired() {
this.gradleBuild.gradleVersion("4.10").build();
this.gradleBuild.gradleVersion("5.6").build();
}
@Test

View File

@@ -53,6 +53,8 @@ class LaunchScriptConfigurationTests {
@Test
void initInfoShortDescriptionUsesDescriptionByDefault() {
given(this.project.getDescription()).willReturn("Project description");
Property<String> baseName = stringProperty("base-name");
given(this.task.getArchiveBaseName()).willReturn(baseName);
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoShortDescription",
"Project description");
}
@@ -68,6 +70,8 @@ class LaunchScriptConfigurationTests {
@Test
void initInfoShortDescriptionUsesSingleLineVersionOfMultiLineProjectDescription() {
given(this.project.getDescription()).willReturn("Project\ndescription");
Property<String> baseName = stringProperty("base-name");
given(this.task.getArchiveBaseName()).willReturn(baseName);
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoShortDescription",
"Project description");
}
@@ -83,6 +87,8 @@ class LaunchScriptConfigurationTests {
@Test
void initInfoDescriptionUsesProjectDescriptionByDefault() {
given(this.project.getDescription()).willReturn("Project description");
Property<String> baseName = stringProperty("base-name");
given(this.task.getArchiveBaseName()).willReturn(baseName);
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoDescription",
"Project description");
}
@@ -90,6 +96,8 @@ class LaunchScriptConfigurationTests {
@Test
void initInfoDescriptionUsesCorrectlyFormattedMultiLineProjectDescription() {
given(this.project.getDescription()).willReturn("The\nproject\ndescription");
Property<String> baseName = stringProperty("base-name");
given(this.task.getArchiveBaseName()).willReturn(baseName);
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoDescription",
"The\n# project\n# description");
}

View File

@@ -149,9 +149,6 @@ public class GradleBuild {
if (this.gradleVersion != null) {
gradleRunner.withGradleVersion(this.gradleVersion);
}
else if (this.dsl == Dsl.KOTLIN) {
gradleRunner.withGradleVersion("4.10.3");
}
List<String> allArguments = new ArrayList<>();
allArguments.add("-PbootVersion=" + getBootVersion());
allArguments.add("--stacktrace");