Skip to content

Commit c76e782

Browse files
committed
Set up for publishing
1 parent a4e0262 commit c76e782

11 files changed

+121
-30
lines changed

annotations/build.gradle.kts

+4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
plugins {
22
kotlin("multiplatform")
3+
id("org.jetbrains.dokka")
4+
id("com.github.ephemient.kotlinx-serialization-contrib.build.publishing")
35
}
46

7+
description = "GenerateEnumSerializer annotation"
8+
59
kotlin {
610
jvm()
711
js(IR) {

build-logic/build.gradle.kts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}

build-logic/settings.gradle.kts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
dependencyResolutionManagement {
2+
repositories {
3+
mavenCentral()
4+
}
5+
6+
versionCatalogs {
7+
create("libs") {
8+
from(files("../gradle/libs.versions.toml"))
9+
}
10+
}
11+
}
12+
13+
rootProject.name = "build-logic"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import groovy.util.Node
2+
import groovy.util.NodeList
3+
4+
plugins {
5+
`maven-publish`
6+
}
7+
8+
publishing {
9+
publications {
10+
withType<MavenPublication>().configureEach {
11+
pom {
12+
url.set("https://github.com/ephemient/kotlinx-serialization-contrib")
13+
description.convention(project.description)
14+
}
15+
}
16+
17+
(findByName("kotlinMultiplatform") as? MavenPublication ?: create<MavenPublication>("maven")).apply {
18+
plugins.withType(JavaPlugin::class) {
19+
extensions.configure<JavaPluginExtension>("java") {
20+
withSourcesJar()
21+
}
22+
from(components["java"])
23+
}
24+
25+
plugins.withId("org.jetbrains.dokka") {
26+
val dokkaJar by tasks.registering(Jar::class) {
27+
description = "Assembles a jar archive containing the Dokka HTML."
28+
group = BasePlugin.BUILD_GROUP
29+
from(tasks.named("dokkaHtml"))
30+
archiveClassifier.set("dokka")
31+
}
32+
tasks.named("assemble") { dependsOn(dokkaJar) }
33+
artifact(dokkaJar)
34+
}
35+
36+
if (name == "kotlinMultiplatform") {
37+
afterEvaluate {
38+
val jvm = findByName("jvm") as? MavenPublication ?: return@afterEvaluate
39+
// Gradle/Kotlin metadata consumers will pick the right platform out of the box,
40+
// but POM consumers won't; force them to JVM.
41+
pom.withXml {
42+
val root = asNode()
43+
val dependencies = ((root["dependencies"] as NodeList).firstOrNull() as Node?)?.apply {
44+
for (child in children().toList()) remove(child as Node)
45+
} ?: root.appendNode("dependencies")
46+
dependencies.appendNode("dependency").apply {
47+
appendNode("groupId", jvm.groupId)
48+
appendNode("artifactId", jvm.artifactId)
49+
appendNode("version", jvm.version)
50+
appendNode("scope", "compile")
51+
}
52+
}
53+
}
54+
}
55+
}
56+
}
57+
58+
repositories {
59+
maven {
60+
name = "GitHubPackages"
61+
url = uri("https://maven.pkg.github.com/ephemient/kotlinx-serialization-contrib")
62+
credentials(PasswordCredentials::class)
63+
}
64+
}
65+
}

build.gradle.kts

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
plugins {
2-
id("com.android.library") apply false
3-
kotlin("jvm") apply false
1+
buildscript {
2+
dependencies {
3+
classpath(libs.android.gradle.plugin)
4+
classpath(libs.dokka.gradle.plugin)
5+
classpath(libs.kotlin.gradle.plugin)
6+
classpath(libs.kotlin.serialization.gradle.plugin)
7+
classpath(libs.ksp.gradle.plugin)
8+
}
9+
10+
repositories {
11+
google()
12+
mavenCentral()
13+
gradlePluginPortal()
14+
}
415
}

gradle.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ android.useAndroidX=true
22
kotlin.code.style=official
33
org.gradle.jvmargs=-Xmx512m -XX:+UseParallelGC
44

5-
androidBuildToolsVersion=7.1.3
6-
kotlinVersion=1.6.10
5+
group=com.github.ephemient.kotlinx-serialization-contrib
6+
version=0.0.1-SNAPSHOT

gradle/libs.versions.toml

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[versions]
2+
android-build = "7.2.0"
23
autoService = "1.0.1"
4+
dokka = "1.6.10"
35
junit4 = "4.13.2"
46
junit-jupiter = "5.8.2"
57
kotlin = "1.6.10"
@@ -9,17 +11,19 @@ ksp = "1.6.10-1.0.4"
911
org-json = "20220320"
1012
robolectric = "4.8.1"
1113

12-
[plugins]
13-
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
14-
1514
[libraries]
15+
android-gradle-plugin = { module = "com.android.tools.build:gradle", version.ref = "android-build" }
1616
auto-service = { module = "com.google.auto.service:auto-service", version.ref = "autoService" }
1717
auto-service-annotations = { module = "com.google.auto.service:auto-service-annotations", version.ref = "autoService" }
18+
dokka-gradle-plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" }
1819
junit4 = { module = "junit:junit", version.ref = "junit4" }
1920
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" }
21+
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
22+
kotlin-serialization-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin" }
2023
kotlinpoet-ksp = { module = "com.squareup:kotlinpoet-ksp", version.ref = "kotlinpoet" }
2124
kotlinx-serialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "kotlinx-serialization" }
2225
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" }
2326
ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }
27+
ksp-gradle-plugin = { module = "com.google.devtools.ksp:symbol-processing-gradle-plugin", version.ref = "ksp" }
2428
org-json = { module = "org.json:json", version.ref = "org-json" }
2529
robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" }

json-java/build.gradle.kts

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ plugins {
22
id("com.android.library")
33
kotlin("multiplatform")
44
kotlin("plugin.serialization")
5+
id("org.jetbrains.dokka")
6+
id("com.github.ephemient.kotlinx-serialization-contrib.build.publishing")
57
}
68

9+
description = "JSON-java format for kotlinx.serialization"
10+
711
android {
812
compileSdk = 31
913
defaultConfig {
@@ -14,7 +18,9 @@ android {
1418

1519
kotlin {
1620
jvm()
17-
android()
21+
android {
22+
publishLibraryVariants("release")
23+
}
1824

1925
sourceSets {
2026
getByName("commonMain") {

processor/build.gradle.kts

+4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
plugins {
22
kotlin("jvm")
33
kotlin("kapt")
4+
id("org.jetbrains.dokka")
5+
id("com.github.ephemient.kotlinx-serialization-contrib.build.publishing")
46
}
57

8+
description = "GenerateEnumSerializer KSP processor"
9+
610
kotlin {
711
target {
812
compilations.all {

settings.gradle.kts

+1-20
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,7 @@
11
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
22

33
pluginManagement {
4-
repositories {
5-
google()
6-
mavenCentral()
7-
gradlePluginPortal()
8-
}
9-
10-
plugins {
11-
val androidBuildToolsVersion: String by settings
12-
val kotlinVersion: String by settings
13-
14-
resolutionStrategy {
15-
eachPlugin {
16-
val id = requested.id.id
17-
when {
18-
id.startsWith("com.android.") -> useVersion(androidBuildToolsVersion)
19-
id.startsWith("org.jetbrains.kotlin.") -> useVersion(kotlinVersion)
20-
}
21-
}
22-
}
23-
}
4+
includeBuild("build-logic")
245
}
256

267
dependencyResolutionManagement {

test/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
kotlin("multiplatform")
33
kotlin("plugin.serialization")
4-
alias(libs.plugins.ksp)
4+
id("com.google.devtools.ksp")
55
}
66

77
kotlin {

0 commit comments

Comments
 (0)