I’d like to be able to define a model space using a shared build script like so:
apply from: '../common/gradle/items.gradle'
model {
items {
item1(Item) {
outputDirectory = file('../item1-out')
}
item2(Item) {
outputDirectory = file('../item2-out')
}
}
}
…and then be able to run a single task which has the effect of executing the same JavaExec
task on each of the configured items, substituting the values of outputDirectory
defined in each item in each execution of JavaExec
.
I’m running into 2 problems:
- I’m getting this exception when gradle encounters the
item1
declaration:
> Exception thrown while executing model rule: items{ ... } @ build.gradle line 14, column 5
> Attempt to read a write only view of model of type 'java.lang.Object' given to rule 'items { ... } @ build.gradle line 14, column 5'
- I do not know how to create a single task that repeatedly runs
JavaExec
using the parameters defined in each configuredItem
. What is the best way to accomplish this? Should I create multiple different tasks for each configured item then create an empty task that usesfinalizedBy
to get all the other tasks to run? If so, what does that look like in theItemRules
class?
Here is the shared build script so far:
@Managed
interface Item {
void setOutputDirectory(File directory)
File getOutputDirectory()
}
class ItemRules extends RuleSource {
@Model void items(ModelMap<Item> theItemsMap) {
println 'Configuring items'
}
@Mutate void createExecTask(ModelMap<Task> tasks, ModelMap<Item> theItemsMap) {
// what to do here?
}
}
apply plugin: ItemRules