You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polaris.apache.org by ad...@apache.org on 2026/04/10 15:57:48 UTC
(polaris) branch main updated: Build: replace deprecated Task.getProject() usage at execution time (#4164)
This is an automated email from the ASF dual-hosted git repository.
adutra pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git
The following commit(s) were added to refs/heads/main by this push:
new 23360a0823 Build: replace deprecated Task.getProject() usage at execution time (#4164)
23360a0823 is described below
commit 23360a08232991f9532d11f7a820fe88a01cf302
Author: Alexandre Dutra <ad...@apache.org>
AuthorDate: Fri Apr 10 17:57:44 2026 +0200
Build: replace deprecated Task.getProject() usage at execution time (#4164)
Avoid invoking `Task.getProject()` at execution time, which is deprecated in Gradle 9 and will fail in Gradle 10.
---
.../src/main/kotlin/publishing/maven-utils.kt | 20 ++++++++----
.../src/main/kotlin/publishing/rootProject.kt | 38 ++++++++++++++--------
build-logic/src/main/kotlin/publishing/signing.kt | 4 +--
3 files changed, 39 insertions(+), 23 deletions(-)
diff --git a/build-logic/src/main/kotlin/publishing/maven-utils.kt b/build-logic/src/main/kotlin/publishing/maven-utils.kt
index 406985cf6b..940fb54b9c 100644
--- a/build-logic/src/main/kotlin/publishing/maven-utils.kt
+++ b/build-logic/src/main/kotlin/publishing/maven-utils.kt
@@ -23,7 +23,7 @@ import org.gradle.api.DefaultTask
import org.gradle.api.Project
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.plugins.JavaLibraryPlugin
-import org.gradle.api.provider.ListProperty
+import org.gradle.api.provider.Property
import org.gradle.api.publish.maven.tasks.GenerateMavenPom
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Input
@@ -35,12 +35,18 @@ import org.gradle.kotlin.dsl.withType
@CacheableTask
abstract class GeneratePomProperties : DefaultTask() {
- @Suppress("unused") @get:Input abstract val pomInputs: ListProperty<String>
+ @get:Input abstract val groupId: Property<String>
+
+ @get:Input abstract val artifactId: Property<String>
+
+ @get:Input abstract val projectVersion: Property<String>
@get:OutputDirectory abstract val destinationDir: DirectoryProperty
init {
- pomInputs.convention(listOf(project.group.toString(), project.name, project.version.toString()))
+ groupId.convention(project.provider { project.group.toString() })
+ artifactId.convention(project.name)
+ projectVersion.convention(project.provider { project.version.toString() })
destinationDir.convention(project.layout.buildDirectory.dir("generated/pom-properties"))
}
@@ -48,16 +54,16 @@ abstract class GeneratePomProperties : DefaultTask() {
fun generate() {
val buildDir = destinationDir.get().asFile
buildDir.deleteRecursively()
- val targetDir = buildDir.resolve("META-INF/maven/${project.group}/${project.name}")
+ val targetDir = buildDir.resolve("META-INF/maven/${groupId.get()}/${artifactId.get()}")
targetDir.mkdirs()
targetDir
.resolve("pom.properties")
.writeText(
"""
# Generated by the Apache Polaris build.
- groupId=${project.group}
- artifactId=${project.name}
- version=${project.version}
+ groupId=${groupId.get()}
+ artifactId=${artifactId.get()}
+ version=${projectVersion.get()}
"""
.trimIndent()
)
diff --git a/build-logic/src/main/kotlin/publishing/rootProject.kt b/build-logic/src/main/kotlin/publishing/rootProject.kt
index 24cf1fef01..e7245a92ff 100644
--- a/build-logic/src/main/kotlin/publishing/rootProject.kt
+++ b/build-logic/src/main/kotlin/publishing/rootProject.kt
@@ -86,13 +86,21 @@ internal fun configureOnRootProject(project: Project) =
mustRunAfter("initializeApacheStagingRepository")
+ // Capture project-derived values at configuration time to avoid
+ // Task.getProject() at execution time (deprecated in Gradle 10).
+ val publishingHelperExt = project.extensions.getByType(PublishingHelperExtension::class.java)
+ val nexusPublishExt = project.extensions.getByType(NexusPublishExtension::class.java)
+ val rootProject = project.rootProject
+ val gradle = project.gradle
+ val projectVersion = project.version
+ val projectDir = project.projectDir
+
doFirst {
- val e = project.extensions.getByType(PublishingHelperExtension::class.java)
- val asfName = e.asfProjectId.get()
+ val asfName = publishingHelperExt.asfProjectId.get()
val gitCommitId = GitInfo.memoized(rootProject).gitHead
- val repos = project.extensions.getByType(NexusPublishExtension::class.java).repositories
+ val repos = nexusPublishExt.repositories
val repo = repos.iterator().next()
val stagingRepositoryUrlRegistryRegistration =
@@ -123,16 +131,18 @@ internal fun configureOnRootProject(project: Project) =
"NO STAGING REPOSITORY (no build service) !!"
}
- val asfProject = AsfProject.memoized(project, asfName)
+ val asfProject = AsfProject.memoized(rootProject, asfName)
val asfProjectName =
- e.overrideName.orElse(project.provider { "Apache ${asfProject.name}" }).get()
+ publishingHelperExt.overrideName.orElse("Apache ${asfProject.name}").get()
- val versionNoRc = version.toString().replace("-rc-?[0-9]+".toRegex(), "")
+ val versionNoRc = projectVersion.toString().replace("-rc-?[0-9]+".toRegex(), "")
- val subjectFile = e.distributionFile("vote-email-subject.txt").relativeTo(projectDir)
- val bodyFile = e.distributionFile("vote-email-body.txt").relativeTo(projectDir)
+ val subjectFile =
+ publishingHelperExt.distributionFile("vote-email-subject.txt").relativeTo(projectDir)
+ val bodyFile =
+ publishingHelperExt.distributionFile("vote-email-body.txt").relativeTo(projectDir)
- val emailSubject = "[VOTE] Release $asfProjectName $version"
+ val emailSubject = "[VOTE] Release $asfProjectName $projectVersion"
subjectFile.writeText(emailSubject)
val emailBody =
@@ -142,12 +152,12 @@ internal fun configureOnRootProject(project: Project) =
I propose that we release the following RC as the official
$asfProjectName $versionNoRc release.
- * This corresponds to the tag: apache-$asfName-$version
- * https://github.com/apache/$asfName/commits/apache-$asfName-$version
+ * This corresponds to the tag: apache-$asfName-$projectVersion
+ * https://github.com/apache/$asfName/commits/apache-$asfName-$projectVersion
* https://github.com/apache/$asfName/tree/$gitCommitId
The release tarball, signature, and checksums are here:
- * https://dist.apache.org/repos/dist/dev/$asfName/apache-$asfName-$version
+ * https://dist.apache.org/repos/dist/dev/$asfName/apache-$asfName-$projectVersion
You can find the KEYS file here:
* https://downloads.apache.org/$asfName/KEYS
@@ -159,7 +169,7 @@ internal fun configureOnRootProject(project: Project) =
Please vote in the next 72 hours.
- [ ] +1 Release this as Apache $asfName $version
+ [ ] +1 Release this as Apache $asfName $projectVersion
[ ] +0
[ ] -1 Do not release this because...
@@ -178,7 +188,7 @@ internal fun configureOnRootProject(project: Project) =
The email for your release vote mail:
-------------------------------------
- Suggested subject: (also in file $subjectFile)
+ Suggested subject: (also in file $subjectFile)
$emailSubject
diff --git a/build-logic/src/main/kotlin/publishing/signing.kt b/build-logic/src/main/kotlin/publishing/signing.kt
index f693d040de..246ffa9a76 100644
--- a/build-logic/src/main/kotlin/publishing/signing.kt
+++ b/build-logic/src/main/kotlin/publishing/signing.kt
@@ -36,11 +36,11 @@ fun Project.signTaskOutputs(task: TaskProvider<*>): Unit {
val signingTask = tasks.register("sign" + task.name.capitalized())
signingTask.configure {
dependsOn(task)
+ val signingExtension = project.extensions.getByType(SigningExtension::class.java)
actions.addLast {
val files = task.get().outputs.files.files
files.forEach { file -> logger.info("Signing $file for '${task.get().path}'") }
- val ext = project.extensions.getByType(SigningExtension::class.java)
- ext.sign(*files.toTypedArray())
+ signingExtension.sign(*files.toTypedArray())
}
}
task.configure { finalizedBy(signingTask) }