How do I make my gradle plugin value depend on whe

2019-08-29 10:40发布

问题:

I have a task changeValue that I want to run optionally. Assume my plugin somePlugin has a task called pluginTask.

When I run gradlew pluginTask I want the value to be someValue.

When I run gradlew changeValue pluginTask I want the value to be somethingElse.

For the 2nd scenario, right now I still get someValue. It's being evaluated during gradle's configuration phase as opposed to execution phase. How can I resolve this?

 String value = 'someValue'

task changeValue() << {
value = 'somethingElse'
}  

somePlugin {
  source = ${value}
}
标签: java gradle