简体   繁体   English

gradle 运行任务的文档?

[英]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.找了半天也没找到gradle run任务的官方文档。 I assume that is because it is actually JavaExec task type.我假设那是因为它实际上是JavaExec任务类型。

It also seems that the run task is only available with the application plugin .似乎run任务仅适用于应用程序插件 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).它的文档提到了一些可用的 arguments,例如--debug-jvm--args (用于将命令行 arguments 传递给应用程序的主要方法)。

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 = ".." } .我实际上想知道如何在命令行上将 arguments 传递给 JVM,即相当于设置application { applicationDefaultJvmArgs = ".." }

Help appreciated!帮助赞赏!

You're right, the run task comes from the application plugin and it is a JavaExec task.没错, run任务来自应用程序插件,它是一个JavaExec任务。

A list of all configuration options is available in the documentation of the JavaExec task JavaExec 任务的文档中提供了所有配置选项的列表

You can configure options in your (groovy-)gradle file like so:您可以像这样在 (groovy-)gradle 文件中配置选项:

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:我现在写了 https://blog.jakubholy.net/2020/customizing-gradle-run-task/它描述了如何自定义run任务以及如何在命令行上自定义它:

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".正如应用程序插件文档所述,您还可以使用 --debug-jvm 启用调试或使用 --args="foo --bar" 指定 arguments。 And you can set application { applicationDefaultJvmArgs= []} to apply both to run and the generated start scripts of your distribution.您可以设置 application { applicationDefaultJvmArgs= []} 以应用运行和生成的分发启动脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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