I created a plugin “MyPlugin” and would like consumers of the plugin allow the to override the prefix of the artifactId. Everything works when using “afterEvaluate” and the overridden value from the consumer is applied. However the afterEvaluate
closure is causing other issues.
Unfortunately the artifactId is not using the lazy provider API and I have to provide a String and I can’t see how I can avoid setting the artifactId
within afterEvaluate
.
My code is basically this:
// My Plugin
abstract class MyPublishingExtension {
abstract val prefix: Property<String>
init {
prefix.convention("default")
}
}
val myPlugin = project.extensions.create<MyPublishingExtension>("myPlugin")
publishing {
publications {
create<MavenPublication>("maven") {
logger.lifecycle(myPlugin.prefix.get()) // default
afterEvaluate {
logger.lifecycle(myPlugin.prefix.get()) // overridden
artifactId = myPlugin.prefix.map { "$it${project.name}" }.get()
}
}
}
}
// Plugin consumer
plugins {
id("myPlugin")
}
myPlugin {
prefix.set("overridden")
}