|
| 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('user') && project.hasProperty('password') && project.hasProperty('deployVersion')) { |
| 15 | + |
| 16 | + // snapshot version differs from normal version |
| 17 | + String versionString = project.getProperty('deployVersion') |
| 18 | + |
| 19 | + |
| 20 | + publishing { |
| 21 | + publications { |
| 22 | + create("mavenJava", MavenPublication) { |
| 23 | + |
| 24 | + versionMapping { |
| 25 | + // resolves dynamic versioning to current version number |
| 26 | + usage('java-api') { |
| 27 | + fromResolutionOf('runtimeClasspath') |
| 28 | + } |
| 29 | + usage('java-runtime') { |
| 30 | + fromResolutionResult() |
| 31 | + } |
| 32 | + } |
| 33 | + pom { |
| 34 | + description = 'OSMoGrid - a tool to generate life like electrical grid models based on publicly available data, mainly OpenStreetMap.' |
| 35 | + name = 'OSMoGrid' |
| 36 | + url = 'https://github.com/ie3-institute/OSMoGrid' |
| 37 | + organization { |
| 38 | + name = 'Institute of Energy Systems, Energy Efficiency and Energy Economics (ie3)/TU Dortmund University' |
| 39 | + url = 'https:www.ie3.tu-dortmund.de/' |
| 40 | + } |
| 41 | + issueManagement { |
| 42 | + system = 'GitHub' |
| 43 | + url = 'https:github.com/ie3-institute/OSMoGrid/issues' |
| 44 | + } |
| 45 | + licenses { |
| 46 | + license { |
| 47 | + name = 'BSD 3-Clause License' |
| 48 | + url = 'https:github.com/ie3-institute/OSMoGrid/blob/master/LICENSE' |
| 49 | + } |
| 50 | + } |
| 51 | + developers { |
| 52 | + developer { |
| 53 | + organization = "Institute of Energy Systems, Energy Efficiency and Energy Economics (ie3)/TU Dortmund University" |
| 54 | + organizationUrl = "https:ie3.etit.tu-dortmund.de" |
| 55 | + } |
| 56 | + } |
| 57 | + scm { |
| 58 | + connection = 'scm:git:git:github.com/ie3-institute/OSMoGrid.git' |
| 59 | + developerConnection = 'scm:git:ssh:github.com:ie3-institute/OSMoGrid.git' |
| 60 | + url = 'https:github.com/ie3-institute/OSMoGrid' |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + removeTestDependenciesFromPom(pom) |
| 65 | + groupId = group |
| 66 | + artifactId = 'OSMoGrid' |
| 67 | + version = versionString |
| 68 | + |
| 69 | + from components.java |
| 70 | + artifact tasks.named("sourcesJar") |
| 71 | + artifact tasks.named("javadocJar") |
| 72 | + } |
| 73 | + } |
| 74 | + repositories { |
| 75 | + maven { |
| 76 | + def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" |
| 77 | + def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/" |
| 78 | + url = versionString.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl |
| 79 | + credentials { |
| 80 | + username project.getProperty('user') |
| 81 | + password project.getProperty('password') |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + signing { |
| 86 | + useInMemoryPgpKeys( |
| 87 | + findProperty('signingKey') as String, |
| 88 | + findProperty('signingPassword') as String |
| 89 | + ) |
| 90 | + sign publications.mavenJava |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + tasks.named("generatePomFileForMavenJavaPublication") { |
| 95 | + destination = layout.buildDirectory.file("generated-pom.xml").get().asFile |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +def removeTestDependenciesFromPom(pom) { |
| 100 | + pom.withXml { |
| 101 | + def root = asNode() |
| 102 | + // eliminate test-scoped dependencies (no need in maven central POMs) |
| 103 | + root.dependencies.removeAll { dep -> |
| 104 | + dep.scope == "test" |
| 105 | + } |
| 106 | + } |
| 107 | +} |
| 108 | + |
| 109 | +/* Maven publish - end */ |
0 commit comments