gradle run任务的文档?

huangapple go评论95阅读模式
英文:

Documentation for the gradle run task?

问题

经过长时间的搜索,我仍然找不到关于 gradle run 任务的任何官方文档。我推测这可能是因为它实际上是 JavaExec 任务类型。

另外,似乎 run 任务只在 application 插件中可用。其文档提到了一些可用的参数,比如 --debug-jvm--args(用于将命令行参数传递给应用程序的主方法)。

实际上,我想找出如何在命令行中将参数传递给 JVM,即相当于设置 application { applicationDefaultJvmArgs = ".." } 这样的效果。

感谢您的帮助!

英文:

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!

答案1

得分: 1

你是对的,run 任务来自应用程序插件,它是一个 JavaExec 任务。

所有配置选项的列表都在 JavaExec 任务的文档 中可用。

你可以在你的(Groovy-)Gradle 文件中进行如下配置:

tasks.named('run', JavaExec) {
    mainClassName = '...MainKt'
    applicationDefaultJvmArgs = [System.getProperty("jvmArgs")]
    classpath = sourceSets.netMain.runtimeClasspath
}
英文:

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
}

答案2

得分: 0

我现在已经写好了 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"]
}

> 正如应用插件文档所述,您还可以通过 --debug-jvm 启用调试,或者通过 --args="foo --bar" 指定参数。而且您可以设置 application { applicationDefaultJvmArgs = []} 来同时应用于运行和分发的生成启动脚本。

英文:

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.

huangapple
  • 本文由 发表于 2020年10月27日 19:45:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/64553760.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定