Skip to content

Commit 25e75c6

Browse files
committed
Merge branch '2.6.x' into 2.7.x
Closes gh-29806
2 parents 15e14e2 + 85d14cd commit 25e75c6

File tree

6 files changed

+19
-86
lines changed

6 files changed

+19
-86
lines changed

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ApplicationPluginAction.java

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@
2020
import java.io.IOException;
2121
import java.io.InputStreamReader;
2222
import java.io.StringWriter;
23-
import java.lang.reflect.Method;
2423
import java.util.concurrent.Callable;
2524

2625
import org.gradle.api.GradleException;
@@ -30,16 +29,10 @@
3029
import org.gradle.api.distribution.DistributionContainer;
3130
import org.gradle.api.file.CopySpec;
3231
import org.gradle.api.file.FileCollection;
33-
import org.gradle.api.internal.IConventionAware;
3432
import org.gradle.api.plugins.ApplicationPlugin;
3533
import org.gradle.api.plugins.ApplicationPluginConvention;
36-
import org.gradle.api.provider.Property;
37-
import org.gradle.api.provider.Provider;
3834
import org.gradle.jvm.application.scripts.TemplateBasedScriptGenerator;
3935
import org.gradle.jvm.application.tasks.CreateStartScripts;
40-
import org.gradle.util.GradleVersion;
41-
42-
import org.springframework.boot.gradle.tasks.application.CreateBootStartScripts;
4336

4437
/**
4538
* Action that is executed in response to the {@link ApplicationPlugin} being applied.
@@ -54,9 +47,9 @@ public void execute(Project project) {
5447
.getPlugin(ApplicationPluginConvention.class);
5548
DistributionContainer distributions = project.getExtensions().getByType(DistributionContainer.class);
5649
Distribution distribution = distributions.create("boot");
57-
configureBaseNameConvention(project, applicationConvention, distribution);
58-
CreateStartScripts bootStartScripts = project.getTasks().create("bootStartScripts",
59-
determineCreateStartScriptsClass());
50+
distribution.getDistributionBaseName()
51+
.convention((project.provider(() -> applicationConvention.getApplicationName() + "-boot")));
52+
CreateStartScripts bootStartScripts = project.getTasks().create("bootStartScripts", CreateStartScripts.class);
6053
bootStartScripts
6154
.setDescription("Generates OS-specific start scripts to run the project as a Spring Boot application.");
6255
((TemplateBasedScriptGenerator) bootStartScripts.getUnixStartScriptGenerator())
@@ -81,45 +74,6 @@ public void execute(Project project) {
8174
distribution.getContents().with(binCopySpec);
8275
}
8376

84-
private Class<? extends CreateStartScripts> determineCreateStartScriptsClass() {
85-
return isGradle64OrLater() ? CreateStartScripts.class : CreateBootStartScripts.class;
86-
}
87-
88-
private boolean isGradle64OrLater() {
89-
return GradleVersion.current().getBaseVersion().compareTo(GradleVersion.version("6.4")) >= 0;
90-
}
91-
92-
@SuppressWarnings("unchecked")
93-
private void configureBaseNameConvention(Project project, ApplicationPluginConvention applicationConvention,
94-
Distribution distribution) {
95-
Method getDistributionBaseName = findMethod(distribution.getClass(), "getDistributionBaseName");
96-
if (getDistributionBaseName != null) {
97-
try {
98-
Property<String> distributionBaseName = (Property<String>) distribution.getClass()
99-
.getMethod("getDistributionBaseName").invoke(distribution);
100-
distributionBaseName.getClass().getMethod("convention", Provider.class).invoke(distributionBaseName,
101-
project.provider(() -> applicationConvention.getApplicationName() + "-boot"));
102-
return;
103-
}
104-
catch (Exception ex) {
105-
// Continue
106-
}
107-
}
108-
if (distribution instanceof IConventionAware) {
109-
((IConventionAware) distribution).getConventionMapping().map("baseName",
110-
() -> applicationConvention.getApplicationName() + "-boot");
111-
}
112-
}
113-
114-
private static Method findMethod(Class<?> type, String name) {
115-
for (Method candidate : type.getMethods()) {
116-
if (candidate.getName().equals(name)) {
117-
return candidate;
118-
}
119-
}
120-
return null;
121-
}
122-
12377
@Override
12478
public Class<? extends Plugin<Project>> getPluginClass() {
12579
return ApplicationPlugin.class;

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import org.gradle.api.tasks.compile.JavaCompile;
4848
import org.gradle.jvm.toolchain.JavaToolchainService;
4949
import org.gradle.jvm.toolchain.JavaToolchainSpec;
50-
import org.gradle.util.GradleVersion;
5150

5251
import org.springframework.boot.gradle.tasks.bundling.BootBuildImage;
5352
import org.springframework.boot.gradle.tasks.bundling.BootJar;
@@ -158,15 +157,9 @@ private void configureBootRunTask(Project project) {
158157
}
159158

160159
private void configureToolchainConvention(Project project, BootRun run) {
161-
if (isGradle67OrLater()) {
162-
JavaToolchainSpec toolchain = project.getExtensions().getByType(JavaPluginExtension.class).getToolchain();
163-
JavaToolchainService toolchainService = project.getExtensions().getByType(JavaToolchainService.class);
164-
run.getJavaLauncher().convention(toolchainService.launcherFor(toolchain));
165-
}
166-
}
167-
168-
private boolean isGradle67OrLater() {
169-
return GradleVersion.current().getBaseVersion().compareTo(GradleVersion.version("6.7")) >= 0;
160+
JavaToolchainSpec toolchain = project.getExtensions().getByType(JavaPluginExtension.class).getToolchain();
161+
JavaToolchainService toolchainService = project.getExtensions().getByType(JavaToolchainService.class);
162+
run.getJavaLauncher().convention(toolchainService.launcherFor(toolchain));
170163
}
171164

172165
private JavaPluginConvention javaPluginConvention(Project project) {

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ResolveMainClassName.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,12 @@ static TaskProvider<ResolveMainClassName> registerForTask(String taskName, Proje
176176
return resolveMainClassNameProvider;
177177
}
178178

179-
@SuppressWarnings("deprecation")
180179
private static String getJavaApplicationMainClass(Convention convention) {
181180
JavaApplication javaApplication = convention.findByType(JavaApplication.class);
182181
if (javaApplication == null) {
183182
return null;
184183
}
185-
try {
186-
return javaApplication.getMainClass().getOrNull();
187-
}
188-
catch (NoSuchMethodError ex) {
189-
return javaApplication.getMainClassName();
190-
}
184+
return javaApplication.getMainClass().getOrNull();
191185
}
192186

193187
private static final class ClassNameReader implements Transformer<String, RegularFile> {

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/application/CreateBootStartScripts.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,7 +25,9 @@
2525
*
2626
* @author Andy Wilkinson
2727
* @since 2.0.0
28+
* @deprecated since 2.5.10 for removal in 2.8.0 in favor of {@link CreateStartScripts}.
2829
*/
30+
@Deprecated
2931
public class CreateBootStartScripts extends CreateStartScripts {
3032

3133
@Override

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoProperties.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -66,14 +66,9 @@ public class BuildInfoProperties implements Serializable {
6666
}
6767

6868
private Provider<String> projectVersion(Project project) {
69-
try {
70-
Provider<String> externalVersionProperty = project.getProviders().gradleProperty("version")
71-
.forUseAtConfigurationTime();
72-
externalVersionProperty.getOrNull();
73-
}
74-
catch (NoSuchMethodError ex) {
75-
// Gradle < 6.5
76-
}
69+
Provider<String> externalVersionProperty = project.getProviders().gradleProperty("version")
70+
.forUseAtConfigurationTime();
71+
externalVersionProperty.getOrNull();
7772
return project.provider(() -> project.getVersion().toString());
7873
}
7974

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/run/BootRun.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -89,14 +89,9 @@ public void exec() {
8989
}
9090

9191
private boolean isJava13OrLater() {
92-
try {
93-
Property<JavaLauncher> javaLauncher = this.getJavaLauncher();
94-
if (javaLauncher.isPresent()) {
95-
return javaLauncher.get().getMetadata().getLanguageVersion().asInt() >= 13;
96-
}
97-
}
98-
catch (NoSuchMethodError ex) {
99-
// Continue
92+
Property<JavaLauncher> javaLauncher = this.getJavaLauncher();
93+
if (javaLauncher.isPresent()) {
94+
return javaLauncher.get().getMetadata().getLanguageVersion().asInt() >= 13;
10095
}
10196
for (Method method : String.class.getMethods()) {
10297
if (method.getName().equals("stripIndent")) {

0 commit comments

Comments
 (0)