Skip to content

Commit 581190d

Browse files
committed
Test the Gradle plugin against 6.7-rc-1
Closes gh-23425
1 parent 3a3e240 commit 581190d

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
public final class GradleCompatibilityExtension implements TestTemplateInvocationContextProvider {
4040

4141
private static final List<String> GRADLE_VERSIONS = Arrays.asList("default", "5.0", "5.1.1", "5.2.1", "5.3.1",
42-
"5.4.1", "5.5.1", "5.6.4", "6.0.1", "6.1.1", "6.2.2", "6.3", "6.4", "6.5.1", "6.6");
42+
"5.4.1", "5.5.1", "5.6.4", "6.0.1", "6.1.1", "6.2.2", "6.3", "6.4", "6.5.1", "6.6", "6.7-rc-1");
4343

4444
@Override
4545
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/GradleBuild.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ void after() {
8686
}
8787

8888
private List<File> pluginClasspath() {
89-
return Arrays.asList(new File("bin"), new File("build/classes/java/main"), new File("build/resources/main"),
90-
new File(pathOfJarContaining(LaunchScript.class)), new File(pathOfJarContaining(ClassVisitor.class)),
89+
return Arrays.asList(new File("bin/main"), new File("build/classes/java/main"),
90+
new File("build/resources/main"), new File(pathOfJarContaining(LaunchScript.class)),
91+
new File(pathOfJarContaining(ClassVisitor.class)),
9192
new File(pathOfJarContaining(DependencyManagementPlugin.class)),
9293
new File(pathOfJarContaining(PropertiesKt.class)), new File(pathOfJarContaining(KotlinLogger.class)),
9394
new File(pathOfJarContaining(KotlinPlugin.class)), new File(pathOfJarContaining(KotlinProject.class)),

0 commit comments

Comments
 (0)