Use absolute path when showing classpath where main class was not found

Closes gh-40463
This commit is contained in:
Andy Wilkinson 2024-04-22 11:16:37 +01:00
parent 172b3d5336
commit ca4d64ed16
4 changed files with 9 additions and 10 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -174,7 +174,7 @@ final class JavaPluginAction implements PluginApplicationAction {
.provider(() -> (String) bootJar.getManifest().getAttributes().get("Start-Class"));
bootJar.getMainClass()
.convention(resolveMainClassName.flatMap((resolver) -> manifestStartClass.isPresent()
? manifestStartClass : resolveMainClassName.get().readMainClassName()));
? manifestStartClass : resolver.readMainClassName()));
bootJar.getTargetJavaVersion()
.set(project.provider(() -> javaPluginExtension(project).getTargetCompatibility()));
bootJar.resolvedArtifacts(runtimeClasspath.getIncoming().getArtifacts().getResolvedArtifacts());

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -153,9 +153,8 @@ public class ResolveMainClassName extends DefaultTask {
String classpath = getClasspath().filter(File::isDirectory)
.getFiles()
.stream()
.map((directory) -> getProject().getProjectDir().toPath().relativize(directory.toPath()))
.map(Path::toString)
.collect(Collectors.joining(","));
.map(File::getAbsolutePath)
.collect(Collectors.joining(File.pathSeparator));
return this.outputFile.map(new ClassNameReader(classpath));
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -96,7 +96,7 @@ class WarPluginAction implements PluginApplicationAction {
.provider(() -> (String) bootWar.getManifest().getAttributes().get("Start-Class"));
bootWar.getMainClass()
.convention(resolveMainClassName.flatMap((resolver) -> manifestStartClass.isPresent()
? manifestStartClass : resolveMainClassName.get().readMainClassName()));
? manifestStartClass : resolver.readMainClassName()));
bootWar.getTargetJavaVersion()
.set(project.provider(() -> javaPluginExtension(project).getTargetCompatibility()));
bootWar.resolvedArtifacts(runtimeClasspath.getIncoming().getArtifacts().getResolvedArtifacts());

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -113,7 +113,7 @@ class BootTestRunIntegrationTests {
else {
assertThat(result.getOutput())
.contains("Main class name has not been configured and it could not be resolved from classpath "
+ String.join(File.separator, "build", "classes", "java", "test"));
+ canonicalPathOf("build/classes/java/test"));
}
}