-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Publish using gradle-maven-publish plugin
- Loading branch information
Showing
3 changed files
with
67 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
204 changes: 65 additions & 139 deletions
204
build-logic/src/main/kotlin/com/ibm/wala/gradle/publishing.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters