Skip to content
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)
- Implementing auto-merge for dependabot PRs [#556](https://github.com/ie3-institute/OSMoGrid/issues/566)

### Changed
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -146,9 +147,8 @@ tasks.withType(Javadoc){
options.encoding = 'UTF-8'
}

task printVersion {
tasks.register("printVersion") {
doLast {
println project.version
}
}

105 changes: 105 additions & 0 deletions gradle/scripts/mavenCentralPublish.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
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"
}
}
}