Hey everyone.
I have a GitHub actions pipeline where I want to do following in multiple separate jobs:
[Build] → [Test] → [Publish]
In the Build
job I publish my library via publishMavenJavaToDistPathRepository
into a local maven folder which is then packaged as build artifacts
In the Test
job I have a separate project consuming the artifacts and integrating my library from Maven using this path.
The Publish
job shoudl then upload the libraries if successful.
But how can I now do a publish of all my files from the and packages to Sonatype OSSRH?
I have a multi-project setup and configure things like here:
// loaded from environment and props files
var sonatypeSigningKeyId = ""
var sonatypeSigningPassword = ""
var sonatypeSigningKey = ""
var ossrhUsername = ""
var ossrhPassword = ""
var sonatypeStagingProfileId = ""
var libDescription = ""
var libAuthorId = ""
var libAuthorName = ""
var libOrgUrl = ""
var libCompany = ""
var libVersion = ""
var libProjectUrl = ""
var libGitUrlHttp = ""
var libGitUrlGit = ""
var libLicenseSpdx = ""
var libLicenseUrl = ""
var libIssuesUrl = ""
// configuring
subprojects {
apply<JavaLibraryPlugin>()
apply<MavenPublishPlugin>()
apply(plugin = "maven-publish")
apply(plugin = "signing")
group = "net.alphatab"
version = libVersion
repositories {
google()
mavenCentral()
}
configure<JavaPluginExtension> {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
withSourcesJar()
withJavadocJar()
}
configure<SigningExtension> {
if (sonatypeSigningKeyId.isNotBlank() && sonatypeSigningKey.isNotBlank() && sonatypeSigningPassword.isNotBlank()) {
useInMemoryPgpKeys(sonatypeSigningKeyId, sonatypeSigningKey, sonatypeSigningPassword)
sign(extensions.getByType<PublishingExtension>().publications["mavenJava"])
}
}
configure<PublishingExtension> {
repositories {
maven {
name = "sonatype"
url = uri(
if (version.toString().endsWith("SNAPSHOT"))
"https://s01.oss.sonatype.org/content/repositories/snapshots/"
else
"https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
)
credentials {
username = ossrhUsername
password = ossrhPassword
}
}
maven {
name = "DistPath"
url = rootProject.projectDir.resolve("dist").toURI()
}
}
publications {
// this publication builds the library and is meant to publish to the local dist folder
create<MavenPublication>("mavenJava") {
from(components["java"])
afterEvaluate {
artifactId = tasks.withType<Jar>().first().archiveBaseName.get()
pom {
description = libDescription
url = libProjectUrl
licenses {
license {
name = libLicenseSpdx
url = libLicenseUrl
}
}
developers {
developer {
id = libAuthorId
name = libAuthorName
organization = libCompany
organizationUrl = libOrgUrl
}
}
scm {
url = libGitUrlHttp
connection = "scm:git:$libGitUrlGit"
developerConnection = "scm:git:$libGitUrlGit"
}
issueManagement {
system = "GitHub"
url = libIssuesUrl
}
}
}
}
}
}
}
Is it maybe somehow possible to create a publication “MavenDist” from the files in the previously published dist
folder and the callpublishMavenDistToSonatypeRepository
? How would such a with keeping all metadata and details look like in Gradle?
Or is there a good alternative to mvn deploy:deploy-file
in the maven-publish
plugin I could use?
Thanks
Daniel