Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read command line gradle vars in class

In my build.gradle I have a task:

run {
  dependsOn ':jar'
  args = [ 'run', project.mainVerticleName, '-cluster', "-launcher-class=$mainClassName", '-Denvironment=development' ]
}

I want to specify command-line args and read them in my class.

I tried:

.\gradlew.bat run -Dhttpport=8825 -Phttpport=8825

but the lines in my class:

log.info "port = ${System.getProperty( 'httpport' )}"
log.info "port = ${System.getenv( 'httpport' )}"

log nulls for both cases.

What am I missing?

like image 384
injecteer Avatar asked Feb 12 '26 06:02

injecteer


1 Answers

This:

.\gradlew.bat run -Dhttpport=8825

you are passing system properties to the gradle itself, not to the process it will start. To make it work this way you need to configure run as follows:

run {
  dependsOn ':jar'
  args = [ 'run', project.mainVerticleName, '-cluster', "-launcher-class=$mainClassName", '-Denvironment=development' ]
  systemProperties System.properties
}

and:

.\gradlew.bat run -Dhttpport=8825

You can also configure system properties using project properties (-P) so:

run {
  dependsOn ':jar'
  args = [ 'run', project.mainVerticleName, '-cluster', "-launcher-class=$mainClassName", '-Denvironment=development' ]
  systemProperties [httpport:project.httpport]
}

and then:

.\gradlew.bat run -Phttpport=8825
like image 108
Opal Avatar answered Feb 15 '26 11:02

Opal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!