Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 29 additions & 21 deletions build-logic/src/main/kotlin/publishing/PublishingHelperPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ constructor(private val softwareComponentFactory: SoftwareComponentFactory) : Pl
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)
val publishing = project.extensions.getByType(PublishingExtension::class.java)
afterEvaluate { sign(publishing.publications.getByName("maven")) }

if (project.hasProperty("useGpgAgent")) {
useGpgCmd()
Expand All @@ -120,32 +118,35 @@ constructor(private val softwareComponentFactory: SoftwareComponentFactory) : Pl
publications {
register<MavenPublication>("maven") {
val mavenPublication = this
afterEvaluate {
// This MUST happen in an 'afterEvaluate' to ensure that the Shadow*Plugin has
// been applied.
if (project.plugins.hasPlugin(ShadowPlugin::class.java)) {
configureShadowPublishing(project, mavenPublication, softwareComponentFactory)
} else {
val component =
components.firstOrNull { c -> c.name == "javaPlatform" || c.name == "java" }
if (component is AdhocComponentWithVariants) {
listOf("testFixturesApiElements", "testFixturesRuntimeElements").forEach { cfg
->
configurations.findByName(cfg)?.apply {
component.addVariantsFromConfiguration(this) { skip() }
}
if (project.plugins.hasPlugin(ShadowPlugin::class.java)) {
configureShadowPublishing(project, mavenPublication, softwareComponentFactory)
} else {
val component =
components.firstOrNull { c -> c.name == "javaPlatform" || c.name == "java" }
if (component is AdhocComponentWithVariants) {
listOf("testFixturesApiElements", "testFixturesRuntimeElements").forEach { cfg ->
configurations.findByName(cfg)?.apply {
component.addVariantsFromConfiguration(this) { skip() }
}
}
}
if (component != null) {
from(component)
}
}

suppressPomMetadataWarningsFor("testFixturesApiElements")
suppressPomMetadataWarningsFor("testFixturesRuntimeElements")
suppressPomMetadataWarningsFor("testFixturesApiElements")
suppressPomMetadataWarningsFor("testFixturesRuntimeElements")

if (project.tasks.findByName("createPolarisSparkJar") != null) {
project.tasks
.matching { task -> task.name == "createPolarisSparkJar" }
.configureEach {
// if the project contains spark client jar, also publish the jar to maven
artifact(project.tasks.named("createPolarisSparkJar").get())
artifact(this)
}

if (project.isSigningEnabled()) {
configure<SigningExtension> { sign(mavenPublication) }
}

if (
Expand All @@ -170,7 +171,7 @@ constructor(private val softwareComponentFactory: SoftwareComponentFactory) : Pl
}

tasks.named("generatePomFileForMavenPublication").configure {
configurePom(project, mavenPublication, this)
configurePom(project, project.parentPomCoordinates(), mavenPublication, this)
}
}
}
Expand All @@ -179,4 +180,11 @@ constructor(private val softwareComponentFactory: SoftwareComponentFactory) : Pl

addAdditionalJarContent(this)
}

private fun Project.parentPomCoordinates(): ParentPomCoordinates? =
if (this == rootProject) {
null
} else {
ParentPomCoordinates(group.toString(), "polaris", version.toString())
}
}
31 changes: 21 additions & 10 deletions build-logic/src/main/kotlin/publishing/configurePom.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,23 @@ import org.gradle.api.publish.maven.MavenPublication
* must be exactly the same when built by a release manager and by someone else to verify the built
* artifact(s).
*/
internal fun configurePom(project: Project, mavenPublication: MavenPublication, task: Task) =
internal data class ParentPomCoordinates(
val groupId: String,
val artifactId: String,
val version: String,
)

internal fun configurePom(
project: Project,
parentPomCoordinates: ParentPomCoordinates?,
mavenPublication: MavenPublication,
task: Task,
) =
mavenPublication.run {
pom {
if (project != project.rootProject) {
if (parentPomCoordinates != null) {
// Non-root Gradle projects.

// Add the license to every pom to make it easier for downstream projects to retrieve the
// license.
licenses {
Expand All @@ -55,11 +68,6 @@ internal fun configurePom(project: Project, mavenPublication: MavenPublication,
}
}

val parent = project.parent!!
val parentGroup = parent.group
val parentName = parent.name
val parentVersion = parent.version

withXml {
val projectNode = asNode()

Expand All @@ -79,14 +87,17 @@ internal fun configurePom(project: Project, mavenPublication: MavenPublication,
}
}
}

// Add GAV to <parent> element
parentNode.appendNode("groupId", parentGroup)
parentNode.appendNode("artifactId", parentName)
parentNode.appendNode("version", parentVersion)
parentNode.appendNode("groupId", parentPomCoordinates.groupId)
parentNode.appendNode("artifactId", parentPomCoordinates.artifactId)
parentNode.appendNode("version", parentPomCoordinates.version)

verifyMandatoryDependencyVersions(projectNode)
}
} else {
// Root Gradle projects.

val mavenPom = this
val effectiveAsfProject = project.provider { EffectiveAsfProject.forProject(project) }
val projectVersion = project.version.toString()
Expand Down
6 changes: 3 additions & 3 deletions build-logic/src/main/kotlin/publishing/rootProject.kt
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ internal fun configureOnRootProject(project: Project) =
sourceTarball.configure { finalizedBy(releaseEmailTemplate) }
}

afterEvaluate {
tasks.named("closeApacheStagingRepository") { mustRunAfter(releaseEmailTemplate) }
}
tasks
.matching { task -> task.name == "closeApacheStagingRepository" }
.configureEach { mustRunAfter(releaseEmailTemplate) }
}
5 changes: 3 additions & 2 deletions build-logic/src/main/kotlin/publishing/shadowPub.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ internal fun configureShadowPublishing(
}
// Sonatype requires the javadoc and sources jar to be present, but the
// Shadow extension does not publish those.
component.addVariantsFromConfiguration(project.configurations.getByName("javadocElements")) {}
component.addVariantsFromConfiguration(project.configurations.getByName("sourcesElements")) {}
project.configurations
.matching { it.name == "javadocElements" || it.name == "sourcesElements" }
.configureEach { component.addVariantsFromConfiguration(this) {} }
mavenPublication.from(component)

// This a replacement to add dependencies to the pom, if necessary. Equivalent to
Expand Down
2 changes: 1 addition & 1 deletion persistence/nosql/persistence/benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
id("polaris-server")
id("com.gradleup.shadow")
id("polaris-server")
alias(libs.plugins.jmh)
}

Expand Down