build.gradle how to apply a closure from another file

j2emanue

I have a closure of defined in a another build.gradle file called other.gradle. Here is the contents:

Closure callback =  {

    productFlavors {  
        ...
        devel {
            ...
        }

        prod {
            ...
        }
    }
}

Now in my build.gradle file I want to call this closure like this:

apply from: 'other.gradle'
productFlavors(callback());

but I keep getting an error that callback() cant be found. Both files are in the same directory. My issue is how do i get the build.gradle file to see the callback closure in the 'other.gradle' file.

Opal

It should be done in the following way:

other.gradle

project.ext.callback = { c ->
    println(c)
}

build.gradle

apply from: 'other.gradle'

callback('a')

Or in same cases callback should be referred via project.instance, e.g. project.callback('a').

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I import a class in gradle outside of build.gradle in a apply from: file

How to call build.gradle from another build.gradle

How to set output file from another gradle build script's task from GradleBuild task?

How to apply and configure gradle plugin in external build file

Android build.gradle importing flavors from another file

How to call a scala method from build.gradle file

In an Android Gradle build, how to exclude dependencies from an included jar file?

How to change value in properties file from gradle build

How to build a WAR file with gradle?

How to include variables from another gradle.properties file?

How to get acces to values from another gradle file?

Gradle: passing parameters to `apply from: <file>`

How to append a closure to another closure?

Unable to apply plugin: 'dexguard' at build.gradle file

Gradle ear build with dependencies from war file

how to execute 'gradle build' command from gradle.build script

How to apply plugin as Map in Gradle's build script?

copy file from one folder to another in gradle

Copy file from another project in a Gradle task

How to check Gradle version number in build file?

How to add a custom repository to gradle build file?

How to change configuration file during gradle build?

How is a token replaced in a file for a Gradle build product?

How to write Gradle build currentVersion to a file

How to regenerate Build Gradle: Module app file

When I import an array from another file, do I take just the data from it or need to "build" the array with how the original file build it?

How to get actual data from one closure into another?

Build a PDF file from parts of another

How to debug a Gradle build.gradle file (in a debugger, with breakpoints)?