I have 2 gradle scripts:
build.gradle and other.gradle
In my build.gradle I have: apply from: 'other.gradle'
task callotherscript << {
thevar = "Thevariableiwanttogetsomeplaceelse"
dosomecommand
In my other.gradle I have:
task dosomecommand(type: Exec) {
executable "someexe"
args "aa", "<myarg>" + <thevar>, "<intomydir>"
}
My question is: How do I get "thevar" from build.gradle so I can use it in other.gradle.
I run: gradle callotherscript
The error message I am seeing is:
Could not find property 'thevar' on task ':dosomecommand'.
I have looked through the cookbook, and every gradle doc I thought was relevant, and I am just not seeing how to do it.
Thanks
Types of Input Arguments When we want to pass input arguments from the Gradle CLI, we have two choices: setting system properties with the -D flag. setting project properties with the -P flag.
The Gradle command-line parser will add all non-option arguments as tasks to be executed to the build. So if we want to pass an extra argument to our build script via the command-line we must use the option -P or --project-prop . With this option we can set a project property and then use it in the build script.
If you are using an IDE, go to run, edit configurations, gradle, select gradle task and update the environment variables. See the picture below. Alternatively, if you are executing gradle commands using terminal, just type 'export KEY=VALUE', and your job is done.
buildscript: This block is used to configure the repositories and dependencies for Gradle. Note: Don't include dependencies here. ( those will be included in the module-level build.gradle) dependencies: This block in buildscript is used to configure dependencies that the Gradle needs to build during the project. Java.
You can declare an extra property, for example on project
:
ext.foo = "bar"
Scripts applied further down can now access the property as foo
.
It's important to understand that tasks don't call other tasks but depend on other tasks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With