Use the Gradle function from another Gradle file

I want to split 300 lines of build.gradle logically into several build files in order to simplify their support and extension.

As I already noticed, you can split gradle tasks into several files and use them with:

apply from: "myGradleFile"

With this approach, I, unfortunately, do not have access to the functions defined in the second build of the script.

Is it also possible to split gradle functions into multiple files?

Example:

Say I have default build.gradle using a task that uses a function

task doSomethingWithMyFunction {
    myFunction()
}

I now have functions.gradle

def myFunction(){
}

, myFunction, functions.gradle, build.gradle

+4
2

, , :

lol.gradle

project.ext.lolFunction = {
   println it
}

build.gradle

apply from: 'lol.gradle'

ext.lolFunction(1)                                                             
+2

All Articles