Reputation: 421
New to gradle and read a few earlier posts on passing variables however none of them have a proper answer. Since gradle has come a long way now and my use case is simple, I hope I get an answer.
I have 2 gradle files - build.gradle docker.gradle
I use apply from: docker.gradle in the buildscript of build.gradle
build.gradle has a variable - ext.appVersion = "1.0"
This variable has to be passed to docker.gradle. What is the best way to achieve this?
I tried extra properties ext.appVersion and that didnt work.
Upvotes: 4
Views: 216
Reputation: 28106
You may share the variables via project properties like so:
project.ext.appVersion = '123123'
But you have to note, the project.ext.appVersion
variable should be declared before the docker.gradle
is applied if you need it at the configuration phase. So, this will work
project.ext.appVersion = '123123'
apply from: 'docker.gradle'
But this won't
apply from: 'docker.gradle'
project.ext.appVersion = '123123'
Upvotes: 3