简体   繁体   中英

Documentation for the gradle run task?

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, ie an equivalent of setting application { applicationDefaultJvmArgs = ".." } .

Help appreciated!

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
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM