Skip to content

Commit 2e3b97a

Browse files
committed
Updated the maven central publishing scripts.
1 parent 220069c commit 2e3b97a

File tree

5 files changed

+151
-111
lines changed

5 files changed

+151
-111
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased/Snapshot]
88

9+
### Changed
10+
- Updated the maven central publishing scripts [#339](https://github.com/ie3-institute/simonaAPI/issues/339)
11+
912
## [0.10.0] - 2025-09-10
1013

1114
### Added

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ apply from: scriptsLocation + 'spotbugs.gradle'
3636
apply from: scriptsLocation + 'sonarqube.gradle'
3737
apply from: scriptsLocation + 'checkJavaVersion.gradle'
3838
apply from: scriptsLocation + 'semVer.gradle'
39-
apply from: scriptsLocation + 'mavenCentralPublish.gradle'
39+
apply from: scriptsLocation + 'uploadToMavenCentralPortal.gradle' // upload for deploy
40+
apply from: scriptsLocation + 'stagingAtMavenCentralPortal.gradle' // stage for deploy
4041
apply from: scriptsLocation + 'jacoco.gradle'
4142
apply from: scriptsLocation + 'documentation.gradle'
4243
apply from: scriptsLocation + 'test.gradle'

gradle/scripts/mavenCentralPublish.gradle

Lines changed: 0 additions & 110 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
tasks.register('stagingAtMavenCentralPortal') {
2+
group = 'publishing'
3+
description = 'Stages uploaded artifacts to Maven Central Portal for manual approval'
4+
5+
doLast {
6+
def username = project.getProperty('mavenCentralUser')
7+
def password = project.getProperty('mavenCentralPassword')
8+
def deployVersion = project.findProperty('deployVersion') ?: project.version
9+
10+
if (!username || !password) {
11+
throw new GradleException("Sonatype credentials not found. Set sonatypeUser and sonatypePassword properties or environment variables.")
12+
}
13+
14+
// Request API for repo key
15+
def repositoryString = providers.exec {
16+
commandLine 'curl',
17+
'-u', "${username}:${password}",
18+
'https://ossrh-staging-api.central.sonatype.com/manual/search/repositories'
19+
}.getStandardOutput().getAsText().get()
20+
21+
def repositoryGroovy = new groovy.json.JsonSlurper().parseText(repositoryString)
22+
def key = repositoryGroovy.repositories[0].key
23+
24+
// Stage via curl
25+
def stageResult = providers.exec {
26+
ignoreExitValue true
27+
commandLine 'curl',
28+
'-u', "${username}:${password}",
29+
'-i', '-X', 'POST', "https://ossrh-staging-api.central.sonatype.com/manual/upload/repository/$key"
30+
}
31+
32+
if (stageResult.result.get().exitValue == 0) {
33+
println "✓ Staging successful!"
34+
println "Check status at: https://central.sonatype.com/publishing/deployments"
35+
} else {
36+
throw new GradleException("Staging failed")
37+
}
38+
}
39+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/* Maven publish - start */
2+
3+
tasks.register("sourcesJar", Jar) {
4+
archiveClassifier.set("sources")
5+
from sourceSets.main.allJava
6+
}
7+
8+
tasks.register("javadocJar", Jar) {
9+
dependsOn tasks.named("javadoc", Javadoc)
10+
archiveClassifier.set("javadoc")
11+
from { tasks.named("javadoc", Javadoc).get().destinationDir }
12+
}
13+
14+
if (project.hasProperty('mavenCentralUser') && project.hasProperty('mavenCentralPassword') && project.hasProperty('deployVersion')) {
15+
16+
// snapshot version differs from normal version
17+
String versionString = project.getProperty('deployVersion')
18+
19+
publishing {
20+
publications {
21+
create("mavenJava", MavenPublication) {
22+
23+
versionMapping {
24+
// resolves dynamic versioning to current version number
25+
usage('java-api') {
26+
fromResolutionOf('runtimeClasspath')
27+
}
28+
usage('java-runtime') {
29+
fromResolutionResult()
30+
}
31+
}
32+
pom {
33+
description = 'API to create modules and add-ons for simona'
34+
name = 'simonaAPI'
35+
url = 'https:github.com/ie3-institute/simonaAPI'
36+
organization {
37+
name = 'Institute of Energy Systems, Energy Efficiency and Energy Economics (ie3)/TU Dortmund University'
38+
url = 'https:www.ie3.tu-dortmund.de/'
39+
}
40+
issueManagement {
41+
system = 'GitHub'
42+
url = 'https:github.com/ie3-institute/simonaAPI/issues'
43+
}
44+
licenses {
45+
license {
46+
name = 'BSD 3-Clause License'
47+
url = 'https:github.com/ie3-institute/simonaAPI/blob/master/LICENSE'
48+
}
49+
}
50+
developers {
51+
developer {
52+
organization = "Institute of Energy Systems, Energy Efficiency and Energy Economics (ie3)/TU Dortmund University"
53+
organizationUrl = "https:ie3.etit.tu-dortmund.de"
54+
}
55+
}
56+
scm {
57+
connection = 'scm:git:git:github.com/ie3-institute/simonaAPI.git'
58+
developerConnection = 'scm:git:ssh:github.com:ie3-institute/simonaAPI.git'
59+
url = 'https:github.com/ie3-institute/simonaAPI'
60+
}
61+
}
62+
63+
removeTestDependenciesFromPom(pom)
64+
groupId = group
65+
artifactId = 'simonaAPI'
66+
version = versionString
67+
68+
from components.java
69+
artifact sourcesJar
70+
artifact javadocJar
71+
}
72+
}
73+
repositories {
74+
maven {
75+
name = "MavenCentral"
76+
url = "https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/"
77+
credentials {
78+
username = project.findProperty('mavenCentralUser')
79+
password = project.findProperty('mavenCentralPassword')
80+
}
81+
}
82+
}
83+
signing {
84+
useInMemoryPgpKeys(
85+
findProperty('signingKey') as String,
86+
findProperty('signingPassword') as String
87+
)
88+
sign publications.mavenJava
89+
}
90+
}
91+
92+
tasks.named("generatePomFileForMavenJavaPublication") {
93+
destination = layout.buildDirectory.file("generated-pom.xml").get().asFile
94+
}
95+
}
96+
97+
def removeTestDependenciesFromPom(pom) {
98+
pom.withXml {
99+
def root = asNode()
100+
// eliminate test-scoped dependencies (no need in maven central POMs)
101+
root.dependencies.removeAll { dep ->
102+
dep.scope == "test"
103+
}
104+
}
105+
}
106+
107+
/* Maven publish - end */

0 commit comments

Comments
 (0)