Hello All,
I’ read this tutorial
https://docs.gradle.org/4.10.3/userguide/custom_plugins.html#sec:implementing_a_dsl
and I extended the object a little bit
package de.docs_as_co.toolchain.publish.askForHelp
import org.gradle.api.Action
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.model.ObjectFactory
class Person {
String name
}
class Group {
Person person
}
class GreetingPluginExtension {
String message
final Group greeter
@javax.inject.Inject
GreetingPluginExtension(ObjectFactory objectFactory) {
greeter = objectFactory.newInstance(Group)
greeter.person = objectFactory.newInstance(Person)
}
void greeter(Action<? super Group> action) {
action.execute(greeter)
}
void person(Action<? super Person> action) {
action.execute(greeter.person)
}
}
class GreetingPlugin implements Plugin<Project> {
void apply(Project project) {
// Create the extension, passing in an ObjectFactory for it to use
def extension = project.extensions.create('greeting', GreetingPluginExtension, project.objects)
project.task('hello') {
doLast {
println "${extension.message} from ${extension.greeter.person.name}"
}
}
}
}
apply plugin: de.docs_as_co.toolchain.publish.askForHelp.GreetingPlugin
greeting {
message = 'Hi'
greeter
person {
name = 'Tom'
}
}
The problem: A group can contain more that one person. How to change the code to achieve this?
Thanks for help
Tom