Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
109 changes: 109 additions & 0 deletions gradle/scripts/mavenCentralPublish.gradle
Original file line number Diff line number Diff line change
@@ -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 */