Skip to content

Commit

Permalink
Publish using gradle-maven-publish plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
liblit committed Jul 22, 2024
1 parent 3e7322d commit de32589
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 139 deletions.
1 change: 1 addition & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies {
implementation(libs.gradle.download.task)
implementation(libs.gradle.errorprone.plugin)
implementation(libs.gradle.goomph.plugin)
implementation(libs.gradle.maven.publish.plugin)
implementation(libs.gradle.spotless.plugin)
}

Expand Down
204 changes: 65 additions & 139 deletions build-logic/src/main/kotlin/com/ibm/wala/gradle/publishing.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,162 +1,88 @@
package com.ibm.wala.gradle

import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.SonatypeHost

plugins {
`java-library`
`java-test-fixtures`
`maven-publish`
signing
id("com.ibm.wala.gradle.subproject")
base
id("com.vanniktech.maven.publish")
}

val isSnapshot = "SNAPSHOT" in version as String
the<PublishingExtension>().repositories.maven {
name = "fakeRemote"
setUrl(rootProject.layout.buildDirectory.dir("maven-fake-remote-repository"))
}

val javaComponent = components["java"] as AdhocComponentWithVariants
///////////////////////////////////////////////////////////////////////////////////////////////////

val allTestFixturesSource: SourceDirectorySet = sourceSets.testFixtures.get().allSource
configure<MavenPublishBaseExtension> {
configureBasedOnAppliedPlugins()
coordinates(artifactId = base.archivesName.get())
publishToMavenCentral(SonatypeHost.DEFAULT)
signAllPublications()

val testFixturesJavadoc by
tasks.existing(Javadoc::class) { setDestinationDir(java.docsDir.get().dir(name).asFile) }
pom {
name = property("POM_NAME") as String
description = "T. J. Watson Libraries for Analysis"
inceptionYear = "2006"
url = "https://github.com/wala/WALA"
val pomUrl = url

val testFixturesJavadocJar by
tasks.registering(Jar::class) {
archiveClassifier = "test-fixtures-javadoc"
from(testFixturesJavadoc.map { it.destinationDir!! })
ciManagement {
system = "GitHub Actions"
url = "https://github.com/wala/WALA/actions"
}

val testFixturesSourcesJar by
tasks.registering(Jar::class) {
archiveClassifier = "test-fixtures-sources"
from(allTestFixturesSource)
developers {
// Current WALA maintainers, alphabetical by ID
mapOf(
"juliandolby" to "Julian Dolby",
"liblit" to "Ben Liblit",
"msridhar" to "Manu Sridharan",
"sjfink" to "Stephen Fink",
)
.forEach { entry ->
developer {
id = entry.key
name = entry.value
url = "https://github.com/{$entry.key}"
}
}
}

val publishing: PublishingExtension by extensions

val mavenPublication =
publishing.publications.create<MavenPublication>("maven") {
from(javaComponent)

groupId = "com.ibm.wala"
artifactId = base.archivesName.get()

val testFixturesCodeElementsNames =
listOf("testFixturesApiElements", "testFixturesRuntimeElements")
testFixturesCodeElementsNames.forEach(this::suppressPomMetadataWarningsFor)
issueManagement {
system = "GitHub"
url = pomUrl.map { "$it/issues" }
}

if (allTestFixturesSource.isEmpty) {
// Test-fixtures jar would be empty except for the manifest, so skip it.
testFixturesCodeElementsNames.forEach {
javaComponent.withVariantsFromConfiguration(configurations[it]) { skip() }
}
} else {
// Test-fixtures jar will have real contents, so add Javadoc and sources
artifact(testFixturesJavadocJar)
artifact(testFixturesSourcesJar)
licenses {
license {
name = "Eclipse Public License v2.0"
url = pomUrl.map { "$it/blob/master/LICENSE" }
}
}

pom {
name = property("POM_NAME") as String
description = "T. J. Watson Libraries for Analysis"
inceptionYear = "2006"
url = "https://github.com/wala/WALA"
val pomUrl = url

ciManagement {
system = "GitHub Actions"
url = "https://github.com/wala/WALA/actions"
}

developers {
// Current WALA maintainers, alphabetical by ID
mapOf(
"juliandolby" to "Julian Dolby",
"liblit" to "Ben Liblit",
"msridhar" to "Manu Sridharan",
"sjfink" to "Stephen Fink",
)
.forEach { entry ->
developer {
id = entry.key
name = entry.value
url = "https://github.com/{$entry.key}"
}
}
}

issueManagement {
system = "GitHub"
url = pomUrl.map { "$it/issues" }
}

licenses {
license {
name = "Eclipse Public License v2.0"
url = pomUrl.map { "$it/blob/master/LICENSE" }
mailingLists {
listOf(
"commits",
"wala",
)
.forEach { topic ->
mailingList {
name = "wala-$topic"
archive = "https://sourceforge.net/p/wala/mailman/wala-$topic"
subscribe = "https://sourceforge.net/projects/wala/lists/wala-$topic"
unsubscribe =
"https://sourceforge.net/projects/wala/lists/wala-$topic/unsubscribe"
post = "wala-$topic@lists.sourceforge.net"
}
}

mailingLists {
listOf(
"commits",
"wala",
)
.forEach { topic ->
mailingList {
name = "wala-$topic"
archive = "https://sourceforge.net/p/wala/mailman/wala-$topic"
subscribe = "https://sourceforge.net/projects/wala/lists/wala-$topic"
unsubscribe =
"https://sourceforge.net/projects/wala/lists/wala-$topic/unsubscribe"
post = "wala-$topic@lists.sourceforge.net"
}
}
}

scm {
url = pomUrl
connection = "scm:git:git://github.com/wala/WALA.git"
developerConnection = "scm:git:ssh://[email protected]/wala/WALA.git"
}
}
}

val repositories: RepositoryHandler = publishing.repositories

val mavenRepository: MavenArtifactRepository =
repositories.maven {
url =
uri(
(if (isSnapshot)
properties.getOrDefault(
"SNAPSHOT_REPOSITORY_URL",
"https://oss.sonatype.org/content/repositories/snapshots/")
else
properties.getOrDefault(
"RELEASE_REPOSITORY_URL",
"https://oss.sonatype.org/service/local/staging/deploy/maven2/"))
as String)
credentials {
username = findProperty("SONATYPE_NEXUS_USERNAME") as String?
password = findProperty("SONATYPE_NEXUS_PASSWORD") as String?
}
scm {
url = pomUrl
connection = "scm:git:git://github.com/wala/WALA.git"
developerConnection = "scm:git:ssh://[email protected]/wala/WALA.git"
}

repositories.maven {
name = "fakeRemote"
setUrl(rootProject.layout.buildDirectory.dir("maven-fake-remote-repository"))
}

signing {
sign(mavenPublication)
setRequired {
// Signatures are a hard requirement if publishing a non-snapshot to a real, remote repository.
!isSnapshot &&
gradle.taskGraph.allTasks.any {
it is PublishToMavenRepository && it.repository == mavenRepository
}
}
}

java {
withJavadocJar()
withSourcesJar()
}
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ errorprone-core = "com.google.errorprone:error_prone_core:2.27.1"
gradle-download-task = "de.undercouch:gradle-download-task:5.6.0"
gradle-errorprone-plugin = "net.ltgt.gradle:gradle-errorprone-plugin:3.1.0"
gradle-goomph-plugin = "com.diffplug.gradle:goomph:3.44.0"
gradle-maven-publish-plugin = "com.vanniktech:gradle-maven-publish-plugin:0.29.0"
gradle-spotless-plugin = { module = "com.diffplug.spotless:spotless-plugin-gradle", version.ref = "spotless" }
gson = "com.google.code.gson:gson:2.11.0"
guava = "com.google.guava:guava:33.2.0-jre"
Expand Down

0 comments on commit de32589

Please sign in to comment.