'What tasks do I need in order to be able to run my Gradle-based Java project from IntelliJ IDEA?

I have a large mostly-Java multi-project Gradle build that I have opened in IntelliJ IDEA. This was imported correctly (as far as I can tell). One of the projects inside this is an old-school Java Swing GUI application.

When I attempt to run its main class from within IntelliJ using the "Run Main.main()" context menu, IntelliJ launches a Gradle task ":folder:project:Main.main()", which fails because of course there is no task in this project's build.gradle called "Main.main()".

The exact error looks like:

Execution failed for task ':folder:project:Main.main()'.
> A problem occurred starting process 'command 'C:/path/to/ojdk8/bin/java.exe''

What exactly am I expected to put into my build.gradle to get this to work?

As a secondary question, is it possible to make such a task agnostic over the actual main()-method containing class? This project contains several such classes that expose different functionality.

For context, I am a long-time Eclipse user evaluating IntelliJ for my organization. This is on IntelliJ IDEA 2022.1, Gradle 5.6.4, OpenJDK 1.8.0_275

I feel like I am missing something completely obvious, but I could not find the answer with any web searching or reading the IntelliJ documentation.



Solution 1:[1]

My mental model of what was happening was wrong. No specific Gradle tasks are required.

It turns out the root cause was Windows. When re-running the task with --stacktrace option I was able to see the actual error, which turned out to be:

CreateProcess error=206: The filename or extension is too long

Googling with this info I found this previous Stackoverflow question. Its answered got me onto the "Shorten command line" flag in the Run/Debug configuration. Setting this to "JAR manifest" solved the problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David Sykes