Skip to content

Commit ca4d64e

Browse files
committed
Use absolute path when showing classpath where main class was not found
Closes gh-40463
1 parent 172b3d5 commit ca4d64e

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 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.
@@ -174,7 +174,7 @@ private TaskProvider<BootJar> configureBootJarTask(Project project,
174174
.provider(() -> (String) bootJar.getManifest().getAttributes().get("Start-Class"));
175175
bootJar.getMainClass()
176176
.convention(resolveMainClassName.flatMap((resolver) -> manifestStartClass.isPresent()
177-
? manifestStartClass : resolveMainClassName.get().readMainClassName()));
177+
? manifestStartClass : resolver.readMainClassName()));
178178
bootJar.getTargetJavaVersion()
179179
.set(project.provider(() -> javaPluginExtension(project).getTargetCompatibility()));
180180
bootJar.resolvedArtifacts(runtimeClasspath.getIncoming().getArtifacts().getResolvedArtifacts());

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 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.
@@ -153,9 +153,8 @@ Provider<String> readMainClassName() {
153153
String classpath = getClasspath().filter(File::isDirectory)
154154
.getFiles()
155155
.stream()
156-
.map((directory) -> getProject().getProjectDir().toPath().relativize(directory.toPath()))
157-
.map(Path::toString)
158-
.collect(Collectors.joining(","));
156+
.map(File::getAbsolutePath)
157+
.collect(Collectors.joining(File.pathSeparator));
159158
return this.outputFile.map(new ClassNameReader(classpath));
160159
}
161160

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 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.
@@ -96,7 +96,7 @@ private TaskProvider<BootWar> configureBootWarTask(Project project) {
9696
.provider(() -> (String) bootWar.getManifest().getAttributes().get("Start-Class"));
9797
bootWar.getMainClass()
9898
.convention(resolveMainClassName.flatMap((resolver) -> manifestStartClass.isPresent()
99-
? manifestStartClass : resolveMainClassName.get().readMainClassName()));
99+
? manifestStartClass : resolver.readMainClassName()));
100100
bootWar.getTargetJavaVersion()
101101
.set(project.provider(() -> javaPluginExtension(project).getTargetCompatibility()));
102102
bootWar.resolvedArtifacts(runtimeClasspath.getIncoming().getArtifacts().getResolvedArtifacts());

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/run/BootTestRunIntegrationTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 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.
@@ -113,7 +113,7 @@ void failsGracefullyWhenNoTestMainMethodIsFound() throws IOException {
113113
else {
114114
assertThat(result.getOutput())
115115
.contains("Main class name has not been configured and it could not be resolved from classpath "
116-
+ String.join(File.separator, "build", "classes", "java", "test"));
116+
+ canonicalPathOf("build/classes/java/test"));
117117
}
118118
}
119119

0 commit comments

Comments
 (0)