Gradle ‘run’ task fails with “No main class specified” despite mainClass being set in build.gradle.kts

  Kiến thức lập trình

Following this post, I’m trying to run a Gradle project using the run task, but I’m encountering an error saying

No main class specified and classpath is not an executable jar

This is happening despite having the mainClass set in the build.gradle.kts file.

Here’s my setup:

In application/build.gradle.kts:

application {
    mainClassName = "com.github.mylibrelab.MyLibreLab"
    mainClass.set(mainClassName)
}

In settings.gradle.kts, the application module is included:

include(
    "application",
    "annotations",
    "dependencies-bom",
    "settings-api",
    "service-manager",
    "util"
)

I’m using Java 11, and here’s how I set up my command prompt environment:

set "PATH=C:WindowsSystem32;"
set "JAVA_HOME=C:Program FilesMicrosoftjdk-11.0.16.101-hotspot"
set "PATH=%JAVA_HOME%bin;%PATH%"

When I run gradlew run --info, I get the following error:

> Task :run FAILED
Caching disabled for task ':run' because:
  Gradle would require more information to cache this task
Task ':run' is not up-to-date because:
  Task has not declared any outputs despite executing actions.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':run'.
> No main class specified and classpath is not an executable jar.

What could be causing this error, and how can I resolve it to successfully run my application using the Gradle run task?

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT