Skip to content

Commit fa7fd88

Browse files
authored
Add publication to Sonatype repository (#6)
Resolves #2
1 parent 032dc2f commit fa7fd88

File tree

7 files changed

+122
-7
lines changed

7 files changed

+122
-7
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22
build/
33
out/
44

5-
.gradle/
5+
.gradle/
6+
7+
# to keep the local secrets from been published
8+
local.properties

build.gradle.kts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import io.gitlab.arturbosch.detekt.Detekt
22
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType
33

4+
@Suppress("DSL_SCOPE_VIOLATION") // TODO: remove when migrate to Gradle 8
45
plugins {
56
alias(libs.plugins.kotlin.mutliplatform)
67
alias(libs.plugins.kotlin.serialization)
@@ -10,7 +11,8 @@ plugins {
1011
alias(libs.plugins.ktlint)
1112
alias(libs.plugins.kotlin.binaryCompatibility)
1213
alias(libs.plugins.kotlin.dokka)
13-
`maven-publish`
14+
alias(libs.plugins.nexus.publish)
15+
id("convention.publication")
1416
}
1517

1618
repositories {
@@ -109,10 +111,27 @@ ktlint {
109111
}
110112
}
111113

112-
private val detektAllTask by tasks.register("detektAll") {
113-
dependsOn(tasks.withType<Detekt>())
114+
afterEvaluate {
115+
val detektAllTask by tasks.register("detektAll") {
116+
dependsOn(tasks.withType<Detekt>())
117+
}
118+
119+
tasks.named("check").configure {
120+
dependsOn(detektAllTask)
121+
}
114122
}
115123

116-
tasks.named("check") {
117-
dependsOn(detektAllTask)
124+
val ossrhUsername: String by project.ext
125+
val ossrhPassword: String by project.ext
126+
127+
nexusPublishing {
128+
this.repositories {
129+
sonatype {
130+
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
131+
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
132+
133+
username.set(ossrhUsername)
134+
password.set(ossrhPassword)
135+
}
136+
}
118137
}

buildSrc/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
repositories {
6+
gradlePluginPortal()
7+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import java.util.Properties
2+
3+
plugins {
4+
`maven-publish`
5+
signing
6+
}
7+
8+
ext["signing.keyId"] = ""
9+
ext["signing.password"] = ""
10+
ext["signing.key"] = ""
11+
ext["ossrhUsername"] = ""
12+
ext["ossrhPassword"] = ""
13+
14+
val secretPropsFile: File = project.rootProject.file("local.properties")
15+
if (secretPropsFile.exists()) {
16+
secretPropsFile.reader().use {
17+
Properties().apply {
18+
load(it)
19+
}
20+
}.onEach { (name, value) ->
21+
ext[name.toString()] = value
22+
}
23+
} else {
24+
ext["signing.keyId"] = System.getenv("SIGNING_KEY_ID")
25+
ext["signing.password"] = System.getenv("SIGNING_PASSWORD")
26+
ext["signing.keys"] = System.getenv("SIGNING_SECRET_KEY")
27+
ext["ossrhUsername"] = System.getenv("OSSRH_USERNAME")
28+
ext["ossrhPassword"] = System.getenv("OSSRH_PASSWORD")
29+
}
30+
31+
val javadocJar by tasks.registering(Jar::class) {
32+
archiveClassifier.set("javadoc")
33+
}
34+
35+
fun getExtraString(name: String) = ext[name]?.toString()
36+
37+
afterEvaluate {
38+
publishing {
39+
40+
publications.withType<MavenPublication> {
41+
// Stub javadoc.jar artifact
42+
artifact(javadocJar)
43+
44+
pom {
45+
name.set("JSON schema validator")
46+
description.set("Multiplatform Kotlin implementation of JSON schema validator")
47+
url.set("https://github.com/OptimumCode/json-schema-validator")
48+
49+
licenses {
50+
license {
51+
name.set("MIT")
52+
url.set("https://opensource.org/licenses/MIT")
53+
}
54+
}
55+
developers {
56+
developer {
57+
id.set("OptimumCode")
58+
name.set("Oleg Smirnov")
59+
email.set("[email protected]")
60+
}
61+
}
62+
scm {
63+
url.set("https://github.com/OptimumCode/json-schema-validator")
64+
}
65+
}
66+
}
67+
}
68+
69+
val signTasks = tasks.withType<Sign>()
70+
// otherwise, the publication fails because some task uses sign output but do not declare that
71+
tasks.withType<AbstractPublishToMaven> {
72+
mustRunAfter(signTasks)
73+
}
74+
}
75+
76+
signing {
77+
useInMemoryPgpKeys(
78+
getExtraString("signing.keyId"),
79+
getExtraString("signing.keys"),
80+
getExtraString("signing.password"),
81+
)
82+
sign(publishing.publications)
83+
}

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
kotlin.code.style=official
22
kotlin.js.compiler=ir
3+
org.gradle.jvmargs=-Xmx1G
4+
org.gradle.java.installations.auto-download=false
35

46
version=0.0.1
57
group=io.github.optimumcode

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ kover = { id = "org.jetbrains.kotlinx.kover", version = "0.7.1" }
1313
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
1414
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version = "11.5.0" }
1515
kotlin-binaryCompatibility = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.13.2" }
16+
nexus-publish = { id = "io.github.gradle-nexus.publish-plugin", version = "1.3.0" }
1617

1718
[libraries]
1819
kotlin-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version = "1.5.1" }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)