From f59ac808e60f2e90f923882309350f59f91a742b Mon Sep 17 00:00:00 2001 From: Philipp Schmelter Date: Tue, 8 Apr 2025 23:33:34 +0200 Subject: [PATCH 1/4] added mavenCentralPublish.gradle --- CHANGELOG.md | 1 + gradle/scripts/mavenCentralPublish.gradle | 109 ++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 gradle/scripts/mavenCentralPublish.gradle diff --git a/CHANGELOG.md b/CHANGELOG.md index 83cf10c4..0fd1a3bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added Marius Staudt to list of reviewers [#516](https://github.com/ie3-institute/OSMoGrid/issues/501) - Create `CITATION.cff` [#531](https://github.com/ie3-institute/OSMoGrid/issues/531) - Implemented GitHub Actions Pipeline [#545](https://github.com/ie3-institute/OSMoGrid/issues/545) +- Added `mavenCentralPublish.gradle` to enable deployment to MavenCentral [#568](https://github.com/ie3-institute/OSMoGrid/issues/568) ### Changed - Rely on Java 17 diff --git a/gradle/scripts/mavenCentralPublish.gradle b/gradle/scripts/mavenCentralPublish.gradle new file mode 100644 index 00000000..e56723bc --- /dev/null +++ b/gradle/scripts/mavenCentralPublish.gradle @@ -0,0 +1,109 @@ +/* Maven publish - start */ + +tasks.register("sourcesJar", Jar) { + archiveClassifier.set("sources") + from sourceSets.main.allJava +} + +tasks.register("javadocJar", Jar) { + dependsOn tasks.named("javadoc", Javadoc) + archiveClassifier.set("javadoc") + from { tasks.named("javadoc", Javadoc).get().destinationDir } +} + +if (project.hasProperty('user') && project.hasProperty('password') && project.hasProperty('deployVersion')) { + + // snapshot version differs from normal version + String versionString = project.getProperty('deployVersion') + + + publishing { + publications { + create("mavenJava", MavenPublication) { + + versionMapping { + // resolves dynamic versioning to current version number + usage('java-api') { + fromResolutionOf('runtimeClasspath') + } + usage('java-runtime') { + fromResolutionResult() + } + } + pom { + description = 'OSMoGrid - a tool to generate life like electrical grid models based on publicly available data, mainly OpenStreetMap.' + name = 'OSMoGrid' + url = 'https://github.com/ie3-institute/OSMoGrid' + organization { + name = 'Institute of Energy Systems, Energy Efficiency and Energy Economics (ie3)/TU Dortmund University' + url = 'https:www.ie3.tu-dortmund.de/' + } + issueManagement { + system = 'GitHub' + url = 'https:github.com/ie3-institute/OSMoGrid/issues' + } + licenses { + license { + name = 'BSD 3-Clause License' + url = 'https:github.com/ie3-institute/OSMoGrid/blob/master/LICENSE' + } + } + developers { + developer { + organization = "Institute of Energy Systems, Energy Efficiency and Energy Economics (ie3)/TU Dortmund University" + organizationUrl = "https:ie3.etit.tu-dortmund.de" + } + } + scm { + connection = 'scm:git:git:github.com/ie3-institute/OSMoGrid.git' + developerConnection = 'scm:git:ssh:github.com:ie3-institute/OSMoGrid.git' + url = 'https:github.com/ie3-institute/OSMoGrid' + } + } + + removeTestDependenciesFromPom(pom) + groupId = group + artifactId = 'OSMoGrid' + version = versionString + + from components.java + artifact tasks.named("sourcesJar") + artifact tasks.named("javadocJar") + } + } + repositories { + maven { + def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" + def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/" + url = versionString.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl + credentials { + username project.getProperty('user') + password project.getProperty('password') + } + } + } + signing { + useInMemoryPgpKeys( + findProperty('signingKey') as String, + findProperty('signingPassword') as String + ) + sign publications.mavenJava + } + } + + tasks.named("generatePomFileForMavenJavaPublication") { + destination = layout.buildDirectory.file("generated-pom.xml").get().asFile + } +} + +def removeTestDependenciesFromPom(pom) { + pom.withXml { + def root = asNode() + // eliminate test-scoped dependencies (no need in maven central POMs) + root.dependencies.removeAll { dep -> + dep.scope == "test" + } + } +} + +/* Maven publish - end */ From 57c53e39428c68caf7c53ee5705463094807cc13 Mon Sep 17 00:00:00 2001 From: Philipp Schmelter Date: Thu, 10 Apr 2025 00:01:26 +0200 Subject: [PATCH 2/4] added mavenCentralPublish.gradle to build.gradle --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 0102867a..51d09255 100644 --- a/build.gradle +++ b/build.gradle @@ -46,6 +46,7 @@ apply from: scriptsLocation + 'scoverage.gradle' // scoverage scala code coverag apply from: scriptsLocation + 'vcs.gradle' apply from: scriptsLocation + 'semVer.gradle' apply from: scriptsLocation + 'tscfg.gradle' +apply from: scriptsLocation + 'mavenCentralPublish.gradle' apply from: scriptsLocation + 'branchName.gradle' // checks naming scheme of branches configurations { From 4f4978c2311c93dec74267e9ee07e850d00ad467 Mon Sep 17 00:00:00 2001 From: Philipp Schmelter Date: Thu, 10 Apr 2025 00:03:20 +0200 Subject: [PATCH 3/4] tasks.register --- build.gradle | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 51d09255..4b01867b 100644 --- a/build.gradle +++ b/build.gradle @@ -149,9 +149,8 @@ tasks.withType(Javadoc){ options.encoding = 'UTF-8' } -task printVersion { +tasks.register("printVersion") { doLast { println project.version } } - From fbb492f83236e8a2d958ffba10fad27f4383e8fa Mon Sep 17 00:00:00 2001 From: Philipp Schmelter Date: Thu, 15 May 2025 14:16:43 +0200 Subject: [PATCH 4/4] remove comments --- gradle/scripts/mavenCentralPublish.gradle | 4 ---- 1 file changed, 4 deletions(-) diff --git a/gradle/scripts/mavenCentralPublish.gradle b/gradle/scripts/mavenCentralPublish.gradle index e56723bc..2e06503c 100644 --- a/gradle/scripts/mavenCentralPublish.gradle +++ b/gradle/scripts/mavenCentralPublish.gradle @@ -1,5 +1,3 @@ -/* Maven publish - start */ - tasks.register("sourcesJar", Jar) { archiveClassifier.set("sources") from sourceSets.main.allJava @@ -105,5 +103,3 @@ def removeTestDependenciesFromPom(pom) { } } } - -/* Maven publish - end */