dependencies {
//..
if (!is_debug) {
getModuleNameStartsWith {
it.startsWith(":module")
}.each {
println("implementation project ===> ${it}")
implementation project(it)
}
}
}
def getModuleNameStartsWith(def start) {
def settings = new File("${rootDir}/settings.gradle")
//根据settings内容找到符合条件(start函数)的module
return names
}
这是我的一个方法,目的是从 settings中找到合适的module然后在app中依赖他们。
我需要在dependencies 的block中implementation project(it),如果把这个implementation放到getModuleNameStartsWith函数中就不行了
Could not find method implementation() for arguments [project ':module1'] on project ':app' of type org.gradle.api.Project. Open File
会提示Could not find method ,即使我在dependencies block中将this传入getModuleNameStartsWith.也不行。所以我应该怎么做?可以让我在函数中调用implementation()方法。
因为我想让我的函数改成这样。
//原函数
if (!is_debug) {
getModuleNameStartsWith {
it.startsWith(":module")
}.each {
println("implementation project ===> ${it}")
implementation project(it)
}
}
dependModules(is_debug){
it.startsWith(":module")
}
//...
def getModuleNameStartsWith(def isDebug, def start)