7

Customizing the Gradle run task

 3 years ago
source link: https://blog.jakubholy.net/2020/customizing-gradle-run-task/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Customizing the Gradle run task

November 11, 2020

The Gradle application plugin provides you with a run task to run your Java application (provided you have set the mainClassName). But how do you customize it, e.g. by setting extra JVM arguments? No amount of searching helped me so I want to share what I have learned.

The run task is of the type JavaExec and accepts the same settings, such as args, debug, debugOptions, jvmArgs, environment, systemProperties. And you can configure it simply by declaring it:

build.gradle
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"]
  args += "my-extra-arg"
}

Now I can run it with e.g. ./gradlew run and all the options will take effect.

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.

(This has been written for Gradle 5 but I imagine it will stay valid for quite a while.)

Are you benefitting from my writing? Consider buying me a coffee or supporting my work via GitHub Sponsors. Thank you! You can also book me for a mentoring / pair-programming session via Codementor or (cheaper) email.

Allow me to write to you!

Let's get in touch! I will occasionally send you a short email with a few links to interesting stuff I found and with summaries of my new blog posts. Max 1-2 emails per month. I read and answer to all replies.


Recommend

  • 7
    • blog.csdn.net 4 years ago
    • Cache

    Gradle之Project,Task

    gradle基本概念 百度百科:Gradle是一个基于Apache Ant和Apache Maven概念的项目自动化构建开源工具。它使用一种基于Groovy的特定领域语言(DSL)来声明项目设置,目前也增加了基于Kotlin语言的kotlin-based DSL,抛弃了基于XML的各种繁琐配置。

  • 4

    New releases of bson4jackson and gradle-download-task « Michel KrämerNew releases of bson4jackson and gradle-download-taskToday I’m happy to an­nounce new ver­sions of bson4­ja...

  • 6
    • michelkraemer.com 3 years ago
    • Cache

    10 recipes for gradle-download-task

    10 recipes for gradle-download-taskI re­ceived a couple of re­quests lately con­cern­ing com­mon prob­lems when down­load­ing files in Gradle build scripts us­ing

  • 3

    New major version 5.0.0 of gradle-download-task « Michel KrämerNew major version 5.0.0 of gradle-download-taskToday, I’m happy to an­nounce the new ma­jor ver­sion 5.0.0 of the pop­u­lar

  • 7
    • michelkraemer.com 3 years ago
    • Cache

    New features in gradle-download-task 3.4.0

    New features in gradle-download-task 3.4.0The new ver­sion 3.4.0 of gradle-down­load-task, a Gradle plug­in provid­ing a ...

  • 12
    • michelkraemer.com 3 years ago
    • Cache

    gradle-download-task 3.3.0

    gradle-download-task 3.3.0 « Michel Krämergradle-download-task 3.3.0The new ver­sion of the Gradle plug­in gradle-down­load-task

  • 4

    gradle-download-task: download files with progressI really like how Gradle dis­plays pro­gress while it’s fetch­ing ar­ti­facts from Maven re­pos­it­or­ies, but I was al­ways won­der­ing why you can­not use the same fu...

  • 5
    • michelkraemer.com 3 years ago
    • Cache

    gradle-download-task 1.2

    gradle-download-task 1.2The new ver­sion of the Gradle plug­in gradle-down­load-task 1.2 has just been re­leased...

  • 6
    • michelkraemer.com 3 years ago
    • Cache

    gradle-download-task 2.0.0

    gradle-download-task 2.0.0 « Michel Krämergradle-download-task 2.0.0The new ver­sion of the Gradle plug­in gradle-down­load-task

  • 6

    Run Your Gradle Build Anywhere with the Gradle Wrapper Gradle is a build automation tool that supports multi-language development. It is helpful to build, test, publish, and deploy softw...

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK