Hug
Hug

Reputation: 597

Calling gradle resValue from another file results in "Error:Gradle DSL method not found: 'resValue()'"

I have the following problem.

I have one main file app.gradle where I call

defaultConfig {
    resValue "string", "hello world", "1234567890"
}

This works ok. Now I'm trying to move that functionality to another file imported on the header with

apply from: "gradle_tasks.gradle"

With the following content:

ext.AddResourcesVariables = { ->
    resValue "string", "hello world", "1234567890"
}

And call it from the main gradle with

defaultConfig {
   AddResourcesVariables()
}

Then I've got the following error:

Error:Gradle DSL method not found: 'resValue()'

Am I missing some import?

Thank you!

Upvotes: 2

Views: 945

Answers (1)

Robert Estivill
Robert Estivill

Reputation: 12497

resValue() is a dsl method from defaultConfig. You can't import it.

You could define a map of [type][name][value] in a different file

ext.valueMap = [
   [type: "string", name: "hello world", value: "1234567890"],
   [type: "string", name: "hello world", value: "1234567890"],
]

And then in the script, you iterate over it

defaultConfig{
  valueMap.each {
    resValue it.type, it.name, it.value
  }
}

Haven't compile it, but should be close.

Upvotes: 3

Related Questions