Skip to content

Instantly share code, notes, and snippets.

@martinda
Created April 22, 2016 19:00
Show Gist options
  • Save martinda/31173a4627c47d38f50b09042cdb4ae0 to your computer and use it in GitHub Desktop.
Save martinda/31173a4627c47d38f50b09042cdb4ae0 to your computer and use it in GitHub Desktop.
Building fruits with Gradle
@Managed
interface FruitBinarySpec extends BinarySpec {
List<String> getFruits()
void setFruits(List<String> fruits)
}
class FruitTask extends SourceTask {
@Input
List<String> fruits
@TaskAction
void peform() {
println(fruits)
}
}
class FruitRules extends RuleSource {
@ComponentType
void registerBinary(TypeBuilder<FruitBinarySpec> builder) {}
@BinaryTasks
void generateTasks(ModelMap<Task> tasks, final FruitBinarySpec binary) {
println("CALL ME !!!")
binary.tasks.each { task ->
def taskName = task.taskName("build",binary.name)
tasks.create(taskName, FruitTask) { fruitTask ->
fruitTask.fruits = binary.fruits
}
}
}
}
apply plugin: FruitRules
model {
components {
redFruits(FruitBinarySpec) {
fruits = ['apple', 'cherry']
}
yellowFruits(FruitBinarySpec) {
fruits = ['banana', 'pina']
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment