Skip to content

Commit 8667e9d

Browse files
committed
Merge branch '2.2.x' into 2.3.x
Closes gh-23426
2 parents d06af28 + 581190d commit 8667e9d

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

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

Lines changed: 31 additions & 4 deletions
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-2020 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.
@@ -18,6 +18,7 @@
1818

1919
import java.io.File;
2020
import java.io.IOException;
21+
import java.lang.reflect.Method;
2122
import java.util.Objects;
2223
import java.util.concurrent.Callable;
2324
import java.util.function.Supplier;
@@ -26,6 +27,7 @@
2627
import org.gradle.api.Project;
2728
import org.gradle.api.file.FileCollection;
2829
import org.gradle.api.plugins.JavaApplication;
30+
import org.gradle.api.provider.Property;
2931

3032
import org.springframework.boot.gradle.dsl.SpringBootExtension;
3133
import org.springframework.boot.loader.tools.MainClassFinder;
@@ -54,11 +56,36 @@ public Object call() throws Exception {
5456
if (springBootExtension != null && springBootExtension.getMainClassName() != null) {
5557
return springBootExtension.getMainClassName();
5658
}
59+
String javaApplicationMainClass = getJavaApplicationMainClass();
60+
return (javaApplicationMainClass != null) ? javaApplicationMainClass : resolveMainClass();
61+
}
62+
63+
@SuppressWarnings("unchecked")
64+
private String getJavaApplicationMainClass() {
5765
JavaApplication javaApplication = this.project.getConvention().findByType(JavaApplication.class);
58-
if (javaApplication != null && javaApplication.getMainClassName() != null) {
59-
return javaApplication.getMainClassName();
66+
if (javaApplication == null) {
67+
return null;
68+
}
69+
Method getMainClass = findMethod(JavaApplication.class, "getMainClass");
70+
if (getMainClass != null) {
71+
try {
72+
Property<String> mainClass = (Property<String>) getMainClass.invoke(javaApplication);
73+
return mainClass.getOrElse(null);
74+
}
75+
catch (Exception ex) {
76+
// Continue
77+
}
78+
}
79+
return javaApplication.getMainClassName();
80+
}
81+
82+
private static Method findMethod(Class<?> type, String name) {
83+
for (Method candidate : type.getMethods()) {
84+
if (candidate.getName().equals(name)) {
85+
return candidate;
86+
}
6087
}
61-
return resolveMainClass();
88+
return null;
6289
}
6390

6491
private String resolveMainClass() {

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleCompatibilityExtension.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ public final class GradleCompatibilityExtension implements TestTemplateInvocatio
4545
JavaVersion javaVersion = JavaVersion.current();
4646
if (javaVersion.isCompatibleWith(JavaVersion.VERSION_14)
4747
|| javaVersion.isCompatibleWith(JavaVersion.VERSION_13)) {
48-
GRADLE_VERSIONS = Arrays.asList("6.3", "6.4.1", "6.5.1", "default");
48+
GRADLE_VERSIONS = Arrays.asList("6.3", "6.4.1", "6.5.1", "default", "6.7-rc-1");
4949
}
5050
else {
51-
GRADLE_VERSIONS = Arrays.asList("5.6.4", "6.3", "6.4.1", "6.5.1", "default");
51+
GRADLE_VERSIONS = Arrays.asList("5.6.4", "6.3", "6.4.1", "6.5.1", "default", "6.7-rc-1");
5252
}
5353
}
5454

0 commit comments

Comments
 (0)