Skip to content

Commit 2c1b202

Browse files
chore: trying to resolve configuration cache issue with publishing.
Can only test it during publication.
1 parent 90d3422 commit 2c1b202

4 files changed

Lines changed: 34 additions & 4 deletions

File tree

build-logic/convention/src/main/kotlin/com/autonomousapps/convention/DagpExtension.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@ public abstract class DagpExtension(
7070
}
7171

7272
project.tasks.named("publishToMavenCentral") { t ->
73+
val key = "is-snapshot"
7374
t.notCompatibleWithConfigurationCache("Cannot serialize object of type DefaultProject")
74-
t.inputs.property("is-snapshot", isSnapshot)
75+
t.inputs.property(key, isSnapshot)
7576

7677
t.doLast {
77-
if (isSnapshot.get()) {
78+
@Suppress("UNCHECKED_CAST")
79+
if ((t.inputs.properties[key] as Provider<Boolean>).get()) {
7880
t.logger.quiet("Browse files at https://central.sonatype.com/service/rest/repository/browse/maven-snapshots/com/autonomousapps/")
7981
} else {
8082
t.logger.quiet(

build-logic/convention/src/main/kotlin/com/autonomousapps/convention/PluginConventionPlugin.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package com.autonomousapps.convention
44

55
import com.autonomousapps.convention.internal.kotlin.KotlinConfigurer
6+
import com.gradle.publish.PublishTask
67
import com.vanniktech.maven.publish.GradlePublishPlugin
78
import com.vanniktech.maven.publish.MavenPublishBaseExtension
89
import org.gradle.api.Plugin
@@ -28,6 +29,9 @@ public abstract class PluginConventionPlugin : Plugin<Project> {
2829
configureKotlin()
2930
configurePlugins()
3031
configurePublishing()
32+
33+
// TODO(tsr): figure out this CC issue.
34+
// disableConfigurationCache()
3135
}
3236

3337
private fun Project.configureGroovy(versionCatalog: VersionCatalog) {
@@ -58,4 +62,13 @@ public abstract class PluginConventionPlugin : Plugin<Project> {
5862
configure(GradlePublishPlugin())
5963
}
6064
}
65+
66+
private fun Project.disableConfigurationCache() {
67+
tasks.withType(PublishTask::class.java).configureEach { t ->
68+
t.notCompatibleWithConfigurationCache("cannot serialize Gradle script object references as these are not supported with the configuration cache.")
69+
}
70+
// tasks.withType(org.gradle.api.publish.maven.tasks.AbstractPublishToMaven::class.java) { t ->
71+
// t.notCompatibleWithConfigurationCache("Various problems")
72+
// }
73+
}
6174
}

build.gradle.kts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ version = VERSION
1818
val isSnapshot: Boolean = project.version.toString().endsWith("SNAPSHOT")
1919
val isRelease: Boolean = !isSnapshot
2020

21+
class IsReleaseSpec(private val isRelease: Boolean) : Spec<Task> {
22+
override fun isSatisfiedBy(element: Task): Boolean {
23+
return isRelease
24+
}
25+
}
26+
2127
dagp {
2228
version(version)
2329
pom {
@@ -319,8 +325,9 @@ val publishToMavenCentral = tasks.named("publishToMavenCentral") {
319325
}
320326

321327
val publishToPluginPortal = tasks.named("publishPlugins") {
328+
val spec = IsReleaseSpec(isRelease)
322329
// Can't publish snapshots to the portal
323-
onlyIf("only publish releases to the plugin portal") { isRelease }
330+
onlyIf("only publish releases to the plugin portal", spec)
324331
shouldRunAfter(publishToMavenCentral)
325332

326333
configureForRelease()

testkit/gradle-testkit-plugin/build.gradle.kts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import org.gradle.kotlin.dsl.assign
22
import org.gradle.plugin.compatibility.compatibility
3+
import org.jetbrains.kotlin.gradle.plugin.extraProperties
34

45
// Copyright (c) 2026. Tony Robalik.
56
// SPDX-License-Identifier: Apache-2.0
@@ -12,6 +13,12 @@ version = "0.19-SNAPSHOT"
1213
val isSnapshot: Boolean = version.toString().endsWith("SNAPSHOT")
1314
val isRelease: Boolean = !isSnapshot
1415

16+
class IsReleaseSpec(private val isRelease: Boolean) : Spec<Task> {
17+
override fun isSatisfiedBy(element: Task): Boolean {
18+
return isRelease
19+
}
20+
}
21+
1522
dagp {
1623
version(version)
1724
pom {
@@ -80,8 +87,9 @@ val publishToMavenCentral = tasks.named("publishToMavenCentral") {
8087
}
8188

8289
val publishToPluginPortal = tasks.named("publishPlugins") {
90+
val spec = IsReleaseSpec(isRelease)
8391
// Can't publish snapshots to the portal
84-
onlyIf { isRelease }
92+
onlyIf("Is not a snapshot", spec)
8593
shouldRunAfter(publishToMavenCentral)
8694

8795
// Note that publishing a release requires a successful smokeTest

0 commit comments

Comments
 (0)