|
| 1 | +import java.util.Properties |
| 2 | + |
| 3 | +plugins { |
| 4 | + `maven-publish` |
| 5 | + signing |
| 6 | +} |
| 7 | + |
| 8 | +ext["signing.key"] = null |
| 9 | +ext["signing.password"] = null |
| 10 | +ext["sonatype.username"] = null |
| 11 | +ext["sonatype.password"] = null |
| 12 | + |
| 13 | +val secretPropsFile = project.rootProject.file("local.properties") |
| 14 | +if (secretPropsFile.exists()) { |
| 15 | + secretPropsFile.reader().use { |
| 16 | + Properties().apply { load(it) } |
| 17 | + }.onEach { (name, value) -> |
| 18 | + ext[name.toString()] = value |
| 19 | + } |
| 20 | +} else { |
| 21 | + ext["signing.key"] = System.getenv("SIGNING_KEY") |
| 22 | + ext["signing.password"] = System.getenv("SIGNING_PASSWORD") |
| 23 | + ext["sonatype.username"] = System.getenv("SONATYPE_USERNAME") |
| 24 | + ext["sonatype.password"] = System.getenv("SONATYPE_PASSWORD") |
| 25 | +} |
| 26 | + |
| 27 | +val javadocJar by tasks.registering(Jar::class) { |
| 28 | + archiveClassifier.set("javadoc") |
| 29 | +} |
| 30 | + |
| 31 | +fun getExtraString(name: String) = ext[name]?.toString() |
| 32 | + |
| 33 | +val isReleaseBuild: Boolean |
| 34 | + get() = properties.containsKey("release") |
| 35 | + |
| 36 | +publishing { |
| 37 | + repositories { |
| 38 | + maven { |
| 39 | + name = "sonatype" |
| 40 | + url = uri( |
| 41 | + if (isReleaseBuild) { |
| 42 | + "https://oss.sonatype.org/service/local/staging/deploy/maven2" |
| 43 | + } else { |
| 44 | + "https://oss.sonatype.org/content/repositories/snapshots" |
| 45 | + } |
| 46 | + ) |
| 47 | + |
| 48 | + credentials { |
| 49 | + username = getExtraString("sonatype.username") |
| 50 | + password = getExtraString("sonatype.password") |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + // Configure all publications |
| 56 | + publications.withType<MavenPublication> { |
| 57 | + val artifactName: String by project |
| 58 | + val artifactDesc: String by project |
| 59 | + val artifactUrl: String by project |
| 60 | + val artifactScm: String by project |
| 61 | + val artifactLicenseName: String by project |
| 62 | + val artifactLicenseUrl: String by project |
| 63 | + |
| 64 | + artifactId = project.name |
| 65 | + |
| 66 | + artifact(javadocJar) |
| 67 | + |
| 68 | + pom { |
| 69 | + name.set(artifactName) |
| 70 | + description.set(artifactDesc) |
| 71 | + url.set(artifactUrl) |
| 72 | + licenses { |
| 73 | + license { |
| 74 | + name.set(artifactLicenseName) |
| 75 | + url.set(artifactLicenseUrl) |
| 76 | + distribution.set("repo") |
| 77 | + } |
| 78 | + } |
| 79 | + developers { |
| 80 | + developer { |
| 81 | + id.set("iNoles") |
| 82 | + } |
| 83 | + developer { |
| 84 | + id.set("kittinunf") |
| 85 | + } |
| 86 | + } |
| 87 | + contributors { |
| 88 | + } |
| 89 | + scm { |
| 90 | + connection.set(artifactScm) |
| 91 | + developerConnection.set(artifactScm) |
| 92 | + url.set(artifactUrl) |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +signing { |
| 99 | + val signingKey = project.ext["signing.key"] as? String |
| 100 | + val signingPassword = project.ext["signing.password"] as? String |
| 101 | + if (signingKey == null || signingPassword == null) return@signing |
| 102 | + |
| 103 | + useInMemoryPgpKeys(signingKey, signingPassword) |
| 104 | + sign(publishing.publications) |
| 105 | +} |
0 commit comments