Thomas Keller
09/11/2024, 3:58 PMafterEvaluate {} block, because only then my build.gradle.kts / custom extension configured values became available, but for a specific upstream plugin this no longer works, because I have to configure things early. Is there a better way of achieving this, i.e. another callback that is run in configuration phase after the build script has been evaluated?Martin
09/11/2024, 4:00 PMabstract class MyExtension {
fun doStuff(action: Action<MySpec>) {
// ...
}
}
This way you can run your logic when the user sets the valuesephemient
09/11/2024, 4:02 PMephemient
09/11/2024, 4:04 PMabstract class MyExtension @Inject constructor(
private val upstreamExtension: UpstreamExtension
) {
val upstreamLazyProperty: Property<Foo>
get() = upstreamExtension.lazyProperty
var upstreamNonLazyProperty: Foo by upstreamExtension::nonLazyPropertyMartin
09/11/2024, 4:04 PMpluginManager.withId() :
val myExtension = extensions.create(...)
pluginManager.withId("myupstream.plugin") {
//
upstreamExtension.property.set(myExtension.property)
}Thomas Keller
09/11/2024, 4:06 PMVampire
09/11/2024, 4:54 PMafterEvaluate, assuming your extension uses Property and the upstream extension uses Property, you can just wire them together anytime, when the value is set is pointless. That's exactly the reason Property existsVampire
09/11/2024, 4:55 PMVampire
09/11/2024, 4:56 PMThomas Keller
09/12/2024, 11:00 AMproject.version property being configured as an output of my build convention, but since this has no lazy-set equivalent as of now (https://github.com/gradle/gradle/issues/13672), I figured I just need to wrap this particular part into an afterEvaluate. This is basically what I'm doing now, the rest of the plugin is configured as it should (VersionConfig comes from the Axion Release Plugin):
afterEvaluate {
val pluginVersion =
try {
lateinit var version: String
configure<VersionConfig> {
version = this.version
}
version
} catch (e: FileNotFoundException) {
logger.warn("Skipping application of version plugin, because we're in a git worktree which is unsupported")
"0.0.1-unknown"
}
project.version = pluginVersion
}ephemient
09/12/2024, 11:05 AMproject.version?
project.version = object {
override fun toString() = try {
lateinit var version: String
configure<VersionConfig> {
version = this.version
}
version
} catch (e: FileNotFoundException) {
logger.warn("Skipping application of version plugin, because we're in a git worktree which is unsupported")
"0.0.1-unknown"
}
}