Reputation: 6195
After a long time of searching I was still not able to find any official documents for the gradle run
task. I assume that is because it is actually JavaExec task type.
It also seems that the run
task is only available with the application plugin. Its docs mention some of the available arguments such as --debug-jvm
and --args
(for passing command-line arguments to the application's main method).
What I actually wanted to find out how I can pass arguments to the JVM on the command-line, i.e. an equivalent of setting application { applicationDefaultJvmArgs = ".." }
.
Help appreciated!
Upvotes: 0
Views: 237
Reputation: 6195
I have now written https://blog.jakubholy.net/2020/customizing-gradle-run-task/ which describes both how to customize the run
task and how to customize it on the command line:
apply plugin: 'application'
mainClassName = "my.app.Main"
run {
debugOptions {
enabled = true
server = true
suspend = false
}
systemProperty("my.defaultLogLevel", "debug")
environment("OTEL_EXPORTER", "zipkin")
jvmArgs=["-javaagent:aws-opentelemetry-agent-0.9.0.jar"]
}
As the application plugin documentation states, you can also enable debugging with --debug-jvm or specify arguments with --args="foo --bar". And you can set application { applicationDefaultJvmArgs= []} to apply both to run and the generated start scripts of your distribution.
Upvotes: 0
Reputation: 3930
You're right, the run
task comes from the application plugin and it is a JavaExec
task.
A list of all configuration options is available in the documentation of the JavaExec task
You can configure options in your (groovy-)gradle file like so:
tasks.named('run', JavaExec) {
mainClassName = '...MainKt'
applicationDefaultJvmArgs = [ System.getProperty("jvmArgs") ]
classpath = sourceSets.netMain.runtimeClasspath
}
Upvotes: 1