From f6bd987991de2cc12ce54e47de3c8156b0e7907a Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 8 Sep 2025 22:07:05 +0800 Subject: [PATCH 1/3] Use the default error message from JavaExec when main class not set Reverts 7c352a4705c9396bd1ddecc374c6e7e86230a9f2. --- docs/changes/README.md | 1 + .../gradle/plugins/shadow/ApplicationPluginTest.kt | 3 ++- .../gradle/plugins/shadow/ShadowApplicationPlugin.kt | 9 +++------ 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/docs/changes/README.md b/docs/changes/README.md index 8c32da476..ae369d4bc 100644 --- a/docs/changes/README.md +++ b/docs/changes/README.md @@ -88,6 +88,7 @@ - For most `ResourceTransformer` users, you need to override the strategy to `INCLUDE` to make them work. - Strongly suggest declaring the `duplicatesStrategy` explicitly in your `ShadowJar` configuration to avoid confusion. - See more details about the strategies at [Handling Duplicates Strategy](https://gradleup.com/shadow/configuration/merging/#handling-duplicates-strategy). +- Use the default error message from `JavaExec` when main class 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..0b43c5b65 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,13 +132,10 @@ 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.") - } - task.manifest.attributes[mainClassAttributeKey] = realClass + if (!task.manifest.attributes.contains(mainClassAttributeKey) && !realClass.isNullOrEmpty()) { + task.manifest.attributes[mainClassAttributeKey] = mainClassName.orNull } } } From 01be9086997ecdb33b068c15b7d4c705ae345d42 Mon Sep 17 00:00:00 2001 From: Zongle Wang Date: Mon, 8 Sep 2025 22:15:34 +0800 Subject: [PATCH 2/3] Update src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.kt Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 0b43c5b65..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 @@ -135,7 +135,7 @@ public abstract class ShadowApplicationPlugin : Plugin { val realClass = mainClassName.orNull // Inject the attribute if it is not already present. if (!task.manifest.attributes.contains(mainClassAttributeKey) && !realClass.isNullOrEmpty()) { - task.manifest.attributes[mainClassAttributeKey] = mainClassName.orNull + task.manifest.attributes[mainClassAttributeKey] = realClass } } } From 787b5c78c795aba340ef271f5b86d96f5daa2042 Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 8 Sep 2025 22:17:56 +0800 Subject: [PATCH 3/3] Refine --- docs/changes/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changes/README.md b/docs/changes/README.md index ae369d4bc..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 @@ -88,7 +89,6 @@ - For most `ResourceTransformer` users, you need to override the strategy to `INCLUDE` to make them work. - Strongly suggest declaring the `duplicatesStrategy` explicitly in your `ShadowJar` configuration to avoid confusion. - See more details about the strategies at [Handling Duplicates Strategy](https://gradleup.com/shadow/configuration/merging/#handling-duplicates-strategy). -- Use the default error message from `JavaExec` when main class not set. ([#1725](https://github.com/GradleUp/shadow/pull/1725)) ### Fixed