

Customizing the Gradle run task
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.

Customizing the Gradle run task
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:
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
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 announce new versions of bson4ja...
-
6
10 recipes for gradle-download-taskI received a couple of requests lately concerning common problems when downloading files in Gradle build scripts using
-
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 announce the new major version 5.0.0 of the popular
-
7
New features in gradle-download-task 3.4.0The new version 3.4.0 of gradle-download-task, a Gradle plugin providing a ...
-
12
gradle-download-task 3.3.0 « Michel Krämergradle-download-task 3.3.0The new version of the Gradle plugin gradle-download-task
-
4
gradle-download-task: download files with progressI really like how Gradle displays progress while it’s fetching artifacts from Maven repositories, but I was always wondering why you cannot use the same fu...
-
5
gradle-download-task 1.2The new version of the Gradle plugin gradle-download-task 1.2 has just been released...
-
6
gradle-download-task 2.0.0 « Michel Krämergradle-download-task 2.0.0The new version of the Gradle plugin gradle-download-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