How to pass variables between different gradle scripts?

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 friend .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 that I can use it in other.gradle.

I run: gradle callotherscript

The error message that I see is:

Could not find property 'thevar' on task ': dosomecommand'.

I looked through the cookbook, and every gradle document that I found relevant, and I just don't see how to do it.

thanks

+6
source share
1 answer

You can declare an additional property, for example, on project :

 ext.foo = "bar" 

The scripts applied further down can now access the property as foo .

It is important to understand that tasks do not cause other tasks, but depend on other tasks.

+11
source

Source: https://habr.com/ru/post/946820/


All Articles