Slackbot
05/04/2022, 5:07 AMVampire
05/04/2022, 6:57 AMChris Lee
05/04/2022, 1:52 PMChris Lee
05/04/2022, 2:20 PMZak Taccardi
05/04/2022, 2:47 PMVampire
05/04/2022, 2:54 PMA but have a method that does the configuration and that can then inform interested other parties like plugin B or similar.Zak Taccardi
05/04/2022, 2:56 PMChris Lee
05/04/2022, 2:57 PMZak Taccardi
05/04/2022, 2:57 PMVampire
05/04/2022, 2:59 PMZak Taccardi
05/04/2022, 3:00 PMafterEvaluate but after the property is set.
The property is set once during evaluation, so I need to execute the registered callback immediately once it's setChris Lee
05/04/2022, 3:01 PMfun propertyA(value : String) {
propertyA.set(value)
callbacks.forEach {
it.execute(value)
}
}Zak Taccardi
05/04/2022, 6:36 PMabstract class ModuleConfigPluginExtension @Inject constructor(
project: Project,
objects: ObjectFactory
) {
private val projectPath = project.path
private var module: Module? = null
private val moduleCollection: DomainObjectCollection<Module> = objects.domainObjectSet(Module::class.java)
fun setModule(module: Module) {
if (this.module != null && this.module != module) {
error("`${projectPath}`: Module has already been set with a different value. Module can only be set once")
}
if (this.module == null) {
this.module = module
moduleCollection.add(module)
}
}
fun whenAdded(block: Module.() -> Unit) {
moduleCollection.configureEach {
block(this)
}
}
}
then plugins can use this extension function:
fun Project.whenModuleConfigAdded(action: Module.() -> Unit) {
the<ModuleConfigPluginExtension>().whenAdded(action)
}Chris Lee
05/04/2022, 6:38 PMZak Taccardi
05/04/2022, 6:48 PMafterEvaluate { } - I actually don’t about all evaluation - just evaluation of a specific plugin/extensionChris Lee
05/04/2022, 6:50 PMZak Taccardi
05/04/2022, 6:50 PMProperty/Provider to react to value changes at configuration timeChris Lee
05/04/2022, 6:52 PMChris Lee
05/04/2022, 6:54 PMextensionB.propertyY.set(extensionA.propertyX)Chris Lee
05/04/2022, 6:55 PMextensionB.propertyY.set(extensionA.propertyX.map {
// do some lazy-evaluated stuff here based on propertyX's value
// invoked when propertyY resolved
})