1

I was experimenting with my project's build.gradle. Currently my project consist of several modules, each of these module have common dependencies, such as android support or network library. I'm Experimenting with gradle dependencies. I've declared a group of dependencies named lib_mandatory() in file lib-group.gradle, but when I tried to include it in my app's build.gradle the gradle sync failed.

Error:Could not find method lib_mandatory() for arguments [] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

How can I fix this? or any hints about what this error means?

Update: Here's the lib-group.gradle

def dependencyGroup(Closure closure) {
   closure.delegate = dependencies
   return closure
}
def lib_mandatory = dependencyGroup{
   implementation libraries.rxjava
   implementation libraries.rxandroid
}

and here's the app's build.gradle

apply from: '../lib-group.gradle'
dependencies {
    lib_mandatory()
}
fchristysen
  • 208
  • 1
  • 10
  • Can you provide how you defined that method in your *lib-group.gradle* and how you call it to *app.gradle* –  Nov 15 '17 at 14:32

1 Answers1

0

The approach that is used in that article is a bit different, the article used the function inside the lib-group.gradle and only applied (apply from ...) the lib-group.gradle in the app's build.gradle.

In your approach, you're trying to use the function in the app's build.gradle.

If you want your functions to be accessed from other files, you should use ext instead of def. You might want to read this: Gradle def vs ext