Which command is used with gradle to run/debug groovy main class?

Answered

I created a run configuration for a main method in a gradle/groovy project.

I wonder how to the the command line executed to run thes main method. I notice that groovy/gradle main methods do not display this information and the run panel does not look exactly like described in the IDE help - there are less buttons.

The (only) class that contains the main method:

import org.fusesource.jansi.AnsiConsole

import static org.fusesource.jansi.Ansi.ansi
import static org.fusesource.jansi.Ansi.Color.*

class CliTest2 {
static main(args) {
AnsiConsole.systemInstall();
println ansi().eraseScreen().fg(RED).a("Hello").fg(GREEN).a(" World").reset()
}
}

When running this configuration, I get an output like:

23:55:04: Executing task 'CliTest2.main()'...

> Task :compileJava NO-SOURCE
> Task :compileGroovy
> Task :processResources NO-SOURCE
> Task :classes

> Task :CliTest2.main()
Hello World

What does "Task :CliTest.main()" mean? How can I reproduce it on a terminal? And does the run panel appear with less UI elements?

 

 

For example, when running the same Hello World as groovy script, the run behaves as expected. Sample code:

import org.fusesource.jansi.AnsiConsole

import static org.fusesource.jansi.Ansi.ansi
import static org.fusesource.jansi.Ansi.Color.*

AnsiConsole.systemInstall();
println ansi().eraseScreen().fg(RED).a("Hello").fg(GREEN).a(" World").reset()

Then the command line is printed as expected and the run panel looks like described in the IDE -help.

C:\Users\x7ws\.jdks\adopt-openjdk-15.0.2\bin\java.exe -Dgroovy.home=... C:\Users\...\src\main\groovy\AnsiTest.groovy
Hello World

Process finished with exit code 0

Why is the "gradle/groovy run" different thant other "run"?

 

0
1 comment

In the first ("gradle/groovy run") case, you are executing the Gradle task, see https://www.jetbrains.com/help/idea/work-with-gradle-tasks.html. In the terminal you can reproduce that by changing the working directory to the directory of your program and running the "Gradle compileJava" command, then "gradle compileGroovy" command, and so on. See https://docs.gradle.org/current/userguide/command_line_interface.html

In the second ("groovy script") case, you are running your program via java binary (without Gradle). That is why you see the command as is.  

0

Please sign in to leave a comment.