Skip to content

Commit 9caf319

Browse files
authored
chore: use common kmp plugin (#1012)
1 parent db521c1 commit 9caf319

File tree

8 files changed

+63
-277
lines changed

8 files changed

+63
-277
lines changed

aws-runtime/build.gradle.kts

Lines changed: 33 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,25 @@
22
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5+
import aws.sdk.kotlin.gradle.kmp.*
56

67
description = "AWS client runtime support for generated service clients"
78

89
plugins {
9-
kotlin("multiplatform")
1010
id("org.jetbrains.dokka")
1111
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.12.1"
1212
jacoco
1313
}
1414

15-
val platforms = listOf("common", "jvm")
16-
17-
// Allow subprojects to use internal API's
18-
// See: https://kotlinlang.org/docs/reference/opt-in-requirements.html#opting-in-to-using-api
19-
val optinAnnotations = listOf(
20-
"kotlin.RequiresOptIn",
21-
)
22-
23-
fun projectNeedsPlatform(project: Project, platform: String): Boolean {
24-
val files = project.projectDir.listFiles()
25-
val hasPosix = files.any { it.name == "posix" }
26-
val hasDarwin = files.any { it.name == "darwin" }
27-
28-
if (hasPosix && platform == "darwin") return false
29-
if (hasDarwin && platform == "posix") return false
30-
if (!hasPosix && !hasDarwin && platform == "darwin") return false
31-
// add implicit JVM target if it has a common module
32-
return files.any { it.name == platform || (it.name == "common" && platform == "jvm") }
33-
}
34-
35-
kotlin {
36-
jvm() // Create a JVM target with the default name 'jvm'
37-
}
38-
3915
val sdkVersion: String by project
4016

17+
val coroutinesVersion: String by project
18+
val kotestVersion: String by project
19+
val slf4jVersion: String by project
20+
4121
subprojects {
22+
if (!needsKmpConfigured) return@subprojects
23+
4224
group = "aws.sdk.kotlin"
4325
version = sdkVersion
4426

@@ -47,39 +29,41 @@ subprojects {
4729
plugin("org.jetbrains.dokka")
4830
}
4931

50-
logger.info("configuring: $project")
51-
52-
// this works by iterating over each platform name and inspecting the projects files. If the project contains
53-
// a directory with the corresponding platform name we apply the common configuration settings for that platform
54-
// (which includes adding the multiplatform target(s)). This makes adding platform support easy and implicit in each
55-
// subproject.
56-
platforms.forEach { platform ->
57-
if (projectNeedsPlatform(project, platform)) {
58-
configure(listOf(project)) {
59-
logger.info("${project.name} needs platform: $platform")
60-
apply(from = rootProject.file("gradle/$platform.gradle"))
61-
}
62-
}
63-
}
32+
apply(from = rootProject.file("gradle/publish.gradle"))
6433

6534
kotlin {
6635
explicitApi()
6736

6837
sourceSets {
69-
all {
70-
val srcDir = if (name.endsWith("Main")) "src" else "test"
71-
val resourcesPrefix = if (name.endsWith("Test")) "test-" else ""
72-
// the name is always the platform followed by a suffix of either "Main" or "Test" (e.g. jvmMain, commonTest, etc)
73-
val platform = name.substring(0, name.length - 4)
74-
kotlin.srcDir("$platform/$srcDir")
75-
resources.srcDir("$platform/${resourcesPrefix}resources")
76-
languageSettings.progressiveMode = true
77-
optinAnnotations.forEach { languageSettings.optIn(it) }
38+
// dependencies available for all subprojects
39+
named("commonMain") {
40+
dependencies {
41+
// FIXME - refactor to only projects that need this
42+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
43+
}
44+
}
45+
46+
named("commonTest") {
47+
dependencies {
48+
implementation("io.kotest:kotest-assertions-core:$kotestVersion")
49+
}
50+
}
51+
52+
named("jvmTest") {
53+
dependencies {
54+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-debug:$coroutinesVersion")
55+
implementation("io.kotest:kotest-assertions-core-jvm:$kotestVersion")
56+
implementation("org.slf4j:slf4j-simple:$slf4jVersion")
57+
}
7858
}
7959
}
8060
}
8161

82-
apply(from = rootProject.file("gradle/publish.gradle"))
62+
kotlin.sourceSets.all {
63+
// Allow subprojects to use internal APIs
64+
// See https://kotlinlang.org/docs/reference/opt-in-requirements.html#opting-in-to-using-api
65+
listOf("kotlin.RequiresOptIn").forEach { languageSettings.optIn(it) }
66+
}
8367

8468
dependencies {
8569
dokkaPlugin(project(":dokka-aws"))

build.gradle.kts

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,32 @@
22
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5+
import aws.sdk.kotlin.gradle.kmp.typedProp
56
import java.net.URL
67
import java.time.Duration
7-
import java.util.Properties
8+
9+
buildscript {
10+
dependencies {
11+
// Add our custom gradle plugin(s) to buildscript classpath (comes from github source)
12+
// NOTE: buildscript classpath for the root project is the parent classloader for the subprojects, we
13+
// only need to include it here, imports in subprojects will work automagically
14+
classpath("aws.sdk.kotlin:build-plugins") {
15+
version {
16+
require("0.1.1")
17+
}
18+
}
19+
}
20+
}
821

922
plugins {
1023
kotlin("jvm") version "1.8.22" apply false
1124
id("org.jetbrains.dokka")
1225
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
1326
}
1427

28+
// configures (KMP) subprojects with our own KMP conventions and some default dependencies
29+
apply(plugin = "aws.sdk.kotlin.kmp")
30+
1531
allprojects {
1632
repositories {
1733
mavenLocal()
@@ -75,25 +91,7 @@ subprojects {
7591
}
7692
}
7793

78-
val localProperties: Map<String, Any> by lazy {
79-
val props = Properties()
80-
81-
listOf(
82-
File(rootProject.projectDir, "local.properties"), // Project-specific local properties
83-
File(rootProject.projectDir.parent, "local.properties"), // Workspace-specific local properties
84-
File(System.getProperty("user.home"), ".sdkdev/local.properties"), // User-specific local properties
85-
)
86-
.filter(File::exists)
87-
.map(File::inputStream)
88-
.forEach(props::load)
89-
90-
props.mapKeys { (k, _) -> k.toString() }
91-
}
92-
93-
fun Project.prop(name: String): Any? =
94-
this.properties[name] ?: localProperties[name]
95-
96-
if (project.prop("kotlinWarningsAsErrors")?.toString()?.toBoolean() == true) {
94+
if (project.typedProp<Boolean>("kotlinWarningsAsErrors") == true) {
9795
subprojects {
9896
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
9997
kotlinOptions.allWarningsAsErrors = true
@@ -180,9 +178,6 @@ tasks.register<JavaExec>("ktlintFormat") {
180178
jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
181179
}
182180

183-
// configure coverage for the entire project
184-
apply(from = rootProject.file("gradle/codecoverage.gradle"))
185-
186181
tasks.register("showRepos") {
187182
doLast {
188183
println("All repos:")

gradle/codecoverage.gradle

Lines changed: 0 additions & 113 deletions
This file was deleted.

gradle/common.gradle

Lines changed: 0 additions & 17 deletions
This file was deleted.

gradle/jvm.gradle

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)