Skip to content

Commit 92f7a8b

Browse files
committed
added gradle plugin for publication
1 parent 7c9d270 commit 92f7a8b

File tree

5 files changed

+118
-2
lines changed

5 files changed

+118
-2
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
kotlin("multiplatform") version "1.5.10"
3-
id("maven-publish")
3+
id("convention.publication")
44
}
55

66
group = "com.vdurmont"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
dependencies {
6+
implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.4.32")
7+
}
8+
9+
repositories {
10+
gradlePluginPortal()
11+
mavenCentral()
12+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import java.util.*
2+
3+
plugins {
4+
`maven-publish`
5+
signing
6+
id("org.jetbrains.dokka")
7+
}
8+
9+
val signingKey: String? = System.getenv("SIGNING_SIGNING_KEY")
10+
val signingPassword: String? = System.getenv("SIGNING_PASSWORD")
11+
12+
// Stub secrets to let the project sync and build without the publication values set up
13+
ext["ossrhUsername"] = null
14+
ext["ossrhPassword"] = null
15+
16+
// Grabbing secrets from local.properties file or from environment variables, which could be used on CI
17+
val secretPropsFile = project.rootProject.file("local.properties")
18+
if (secretPropsFile.exists()) {
19+
secretPropsFile.reader().use {
20+
Properties().apply {
21+
load(it)
22+
}
23+
}.onEach { (name, value) ->
24+
ext[name.toString()] = value
25+
}
26+
} else {
27+
ext["ossrhUsername"] = System.getenv("OSSRH_USERNAME")
28+
ext["ossrhPassword"] = System.getenv("OSSRH_PASSWORD")
29+
}
30+
31+
fun getExtraString(name: String) = ext[name]?.toString()
32+
33+
tasks {
34+
val dokkaOutputDir = "$buildDir/dokka"
35+
36+
dokkaHtml {
37+
outputDirectory.set(file(dokkaOutputDir))
38+
}
39+
40+
val deleteDokkaOutputDir by registering(Delete::class) {
41+
delete(dokkaOutputDir)
42+
}
43+
44+
register<Jar>("javadocJar") {
45+
dependsOn(deleteDokkaOutputDir, dokkaHtml)
46+
archiveClassifier.set("javadoc")
47+
from(dokkaOutputDir)
48+
}
49+
}
50+
51+
publishing {
52+
// Configure maven central repository
53+
repositories {
54+
maven {
55+
name = "sonatype"
56+
setUrl("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
57+
credentials {
58+
username = getExtraString("ossrhUsername")
59+
password = getExtraString("ossrhPassword")
60+
}
61+
}
62+
}
63+
64+
// Configure all publications
65+
publications.withType<MavenPublication> {
66+
67+
artifact(tasks.named<Jar>("javadocJar").get())
68+
69+
// Provide artifacts information requited by Maven Central
70+
pom {
71+
name.set("Semver4k")
72+
description.set("Semver Kotlin Multiplatform library")
73+
url.set("https://github.com/voize-gmbh/semver4k")
74+
75+
licenses {
76+
license {
77+
name.set("MIT")
78+
url.set("https://opensource.org/licenses/MIT")
79+
}
80+
}
81+
developers {
82+
developer {
83+
id.set("LeonKiefer")
84+
name.set("Leon Kiefer")
85+
email.set("leon@voize.de")
86+
}
87+
}
88+
scm {
89+
url.set("https://github.com/voize-gmbh/semver4k")
90+
}
91+
}
92+
}
93+
}
94+
95+
if (signingPassword != null) {
96+
signing {
97+
if (signingKey != null) {
98+
useInMemoryPgpKeys(signingKey, signingPassword)
99+
}
100+
sign(publishing.publications)
101+
}
102+
}

settings.gradle.kt

Lines changed: 0 additions & 1 deletion
This file was deleted.

settings.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
rootProject.name = "semver4k"
2+
3+
includeBuild("convention-plugins")

0 commit comments

Comments
 (0)