diff --git a/docs/changes/README.md b/docs/changes/README.md index 8c32da476..90519ea55 100644 --- a/docs/changes/README.md +++ b/docs/changes/README.md @@ -16,6 +16,7 @@ and `META-INF/groovy` will be merged into `META-INF/groovy/org.codehaus.groovy.runtime.ExtensionModule`. - Move injecting `Class-Path` manifest attr logic from `doFirst` into `copy`. ([#1720](https://github.com/GradleUp/shadow/pull/1720)) - Deprecate `InheritManifest`. ([#1722](https://github.com/GradleUp/shadow/pull/1722)) +- Use default `JavaExec` error message when main class is not set. ([#1725](https://github.com/GradleUp/shadow/pull/1725)) ### Fixed diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationPluginTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationPluginTest.kt index 386311bf0..8321254b0 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationPluginTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationPluginTest.kt @@ -177,7 +177,8 @@ class ApplicationPluginTest : BasePluginTest() { val result = runWithFailure(runShadowPath) assertThat(result.output).contains( - "The main class must be specified and not left empty in `application.mainClass` or manifest attributes.", + "Error: Could not find or load main class", + "Caused by: java.lang.ClassNotFoundException:", ) } diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.kt index 91b7facf1..8505c727e 100644 --- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.kt +++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.kt @@ -132,12 +132,9 @@ public abstract class ShadowApplicationPlugin : Plugin { tasks.shadowJar.configure { task -> task.inputs.property("mainClassName", mainClassName) task.doFirst("Set $mainClassAttributeKey attribute in the manifest") { + val realClass = mainClassName.orNull // Inject the attribute if it is not already present. - if (!task.manifest.attributes.contains(mainClassAttributeKey)) { - val realClass = mainClassName.orNull - if (realClass.isNullOrEmpty()) { - error("The main class must be specified and not left empty in `application.mainClass` or manifest attributes.") - } + if (!task.manifest.attributes.contains(mainClassAttributeKey) && !realClass.isNullOrEmpty()) { task.manifest.attributes[mainClassAttributeKey] = realClass } }