11/*
22 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33 * SPDX-License-Identifier: Apache-2.0.
4- *
54 */
5+
6+ import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest
7+ import org.jetbrains.kotlin.gradle.tasks.KotlinTest
8+
69plugins {
7- kotlin(" jvm " )
10+ kotlin(" multiplatform " )
811 `maven- publish`
912 id(" org.jetbrains.dokka" )
1013}
1114
15+ val platforms = listOf (" common" , " jvm" )
16+
1217val sdkVersion: String by project
1318val kotlinVersion: String by project
1419val coroutinesVersion: String by project
@@ -17,149 +22,119 @@ val kotestVersion: String by project
1722val optinAnnotations = listOf (
1823 " aws.smithy.kotlin.runtime.util.InternalApi" ,
1924 " aws.sdk.kotlin.runtime.InternalSdkApi" ,
25+ " kotlin.RequiresOptIn" ,
2026)
2127
28+ kotlin {
29+ jvm() // Create a JVM target with the default name 'jvm'
30+ }
31+
2232subprojects {
2333 group = " aws.sdk.kotlin"
2434 version = sdkVersion
2535
2636 apply {
27- plugin(" org.jetbrains.kotlin.jvm " )
37+ plugin(" org.jetbrains.kotlin.multiplatform " )
2838 plugin(" org.jetbrains.dokka" )
2939 }
3040
31- // have generated sdk's opt-in to internal runtime features
32- kotlin.sourceSets.all {
33- optinAnnotations.forEach { languageSettings.optIn(it) }
34- }
41+ logger.info(" configuring: $project " )
3542
36- kotlin {
37- sourceSets.getByName(" main" ) {
38- kotlin.srcDir(" common/src" )
39- kotlin.srcDir(" generated-src/main/kotlin" )
40- }
41- sourceSets.getByName(" test" ) {
42- kotlin.srcDir(" common/test" )
43- kotlin.srcDir(" generated-src/test" )
44-
45- dependencies {
46- implementation(kotlin(" test-junit5" ))
47- implementation(" org.jetbrains.kotlin:kotlin-test-common:$kotlinVersion " )
48- implementation(" org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion " )
49- implementation(project(" :aws-runtime:testing" ))
50- implementation(" io.kotest:kotest-assertions-core:$kotestVersion " )
51- }
43+ platforms.forEach { platform ->
44+ configure(listOf (project)) {
45+ apply (from = rootProject.file(" gradle/$platform .gradle" ))
5246 }
5347 }
5448
55- tasks.withType< org.jetbrains.dokka.gradle.DokkaTaskPartial > ().configureEach {
56- dokkaSourceSets {
57- named(" main" ) {
58- platform.set(org.jetbrains.dokka.Platform .jvm)
59- sourceRoots.from(kotlin.sourceSets.getByName(" main" ).kotlin.srcDirs)
49+ kotlin {
50+ sourceSets {
51+ all {
52+ val srcDir = if (name.endsWith(" Main" )) " src" else " test"
53+ val resourcesPrefix = if (name.endsWith(" Test" )) " test-" else " "
54+ // the name is always the platform followed by a suffix of either "Main" or "Test" (e.g. jvmMain, commonTest, etc)
55+ val platform = name.substring(0 , name.length - 4 )
56+ kotlin.srcDir(" $platform /$srcDir " )
57+ resources.srcDir(" $platform /${resourcesPrefix} resources" )
58+
59+ languageSettings.progressiveMode = true
60+
61+ // have generated sdk's opt-in to internal runtime features
62+ optinAnnotations.forEach { languageSettings.optIn(it) }
6063 }
61- }
62- }
63-
64- tasks.test {
65- useJUnitPlatform()
66- testLogging {
67- events(" passed" , " skipped" , " failed" )
68- showStandardStreams = true
69- showStackTraces = true
70- showExceptions = true
71- exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat .FULL
72- }
73- }
74-
75-
76- tasks.compileKotlin {
77- kotlinOptions {
78- jvmTarget = " 1.8" // this is the default but it's better to be explicit (e.g. it may change in Kotlin 1.5)
79- allWarningsAsErrors = false // FIXME Tons of errors occur in generated code
80- }
81- }
82- tasks.compileTestKotlin {
83- kotlinOptions {
84- jvmTarget = " 1.8" // this is the default but it's better to be explicit (e.g. it may change in Kotlin 1.5)
85- allWarningsAsErrors = false // FIXME Tons of errors occur in generated code
86- // Enable coroutine runTests in 1.6.10
87- // NOTE: may be removed after coroutines-test runTests becomes stable
88- freeCompilerArgs = freeCompilerArgs + " -opt-in=kotlin.RequiresOptIn"
89- }
90- }
9164
92- // FIXME - we can remove this when we implement generated services as multiplatform.
93- setOutgoingVariantMetadata()
65+ getByName(" commonMain" ) {
66+ kotlin.srcDir(" generated-src/main/kotlin" )
67+ }
9468
95- val sourcesJar by tasks.creating(Jar ::class ) {
96- group = " publishing"
97- description = " Assembles Kotlin sources jar"
98- classifier = " sources"
99- from(sourceSets.getByName(" main" ).allSource)
100- }
69+ getByName(" commonTest" ) {
70+ kotlin.srcDir(" generated-src/test" )
10171
102- // FIXME - kotlin multiplatform configures publications for you so when we switch we can remove this
103- // and just apply "publish.gradle" from the set of root gradle scripts (just like we do for the runtime)
104- plugins.apply (" maven-publish" )
105- publishing {
106- publications {
107- create<MavenPublication >(" sdk" ){
108- from(components[" java" ])
109- artifact(sourcesJar)
72+ dependencies {
73+ implementation(" org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion " )
74+ implementation(project(" :aws-runtime:testing" ))
75+ }
11076 }
11177 }
112- }
113-
114- apply (from = rootProject.file(" gradle/publish.gradle" ))
115-
116- if (project.file(" e2eTest" ).exists()) {
11778
118- kotlin.target.compilations {
119- val main by getting
120- val e2eTest by creating {
121- defaultSourceSet {
122- kotlin.srcDir(" e2eTest" )
123- dependencies {
124- implementation(main.compileDependencyFiles + main.runtimeDependencyFiles + main.output.classesDirs)
79+ if (project.file(" e2eTest" ).exists()) {
80+ jvm().compilations {
81+ val main by getting
82+ val e2eTest by creating {
83+ defaultSourceSet {
84+ kotlin.srcDir(" e2eTest" )
85+
86+ dependencies {
87+ // Compile against the main compilation's compile classpath and outputs:
88+ implementation(main.compileDependencyFiles + main.output.classesDirs)
89+
90+ implementation(kotlin(" test" ))
91+ implementation(kotlin(" test-junit5" ))
92+ implementation(project(" :aws-runtime:testing" ))
93+ implementation(project(" :tests:e2e-test-util" ))
94+ }
95+ }
12596
126- implementation(kotlin( " test " ))
127- implementation(kotlin( " test-junit5 " ))
128- implementation(project( " :aws-runtime:testing " ))
129- implementation(project( " :tests:e2e-test-util " ))
97+ kotlinOptions {
98+ // Enable coroutine runTests in 1.6.10
99+ // NOTE: may be removed after coroutines-test runTests becomes stable
100+ freeCompilerArgs = freeCompilerArgs + " -opt-in=kotlin.RequiresOptIn "
130101 }
131- }
132- kotlinOptions {
133- // Enable coroutine runTests in 1.6.10
134- // NOTE: may be removed after coroutines-test runTests becomes stable
135- freeCompilerArgs = freeCompilerArgs + " -opt-in=kotlin.RequiresOptIn"
136- }
137102
138- tasks.register<Test >(" e2eTest" ) {
139- description = " Run e2e service tests"
140- group = " verification"
141- classpath = compileDependencyFiles + runtimeDependencyFiles
142- testClassesDirs = output.classesDirs
143- useJUnitPlatform()
144- testLogging {
145- events(" passed" , " skipped" , " failed" )
146- showStandardStreams = true
147- showStackTraces = true
148- showExceptions = true
149- exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat .FULL
103+ tasks.register<Test >(" e2eTest" ) {
104+ description = " Run e2e service tests"
105+ group = " verification"
106+
107+ // Run the tests with the classpath containing the compile dependencies (including 'main'),
108+ // runtime dependencies, and the outputs of this compilation:
109+ classpath = compileDependencyFiles + runtimeDependencyFiles + output.allOutputs
110+
111+ // Run only the tests from this compilation's outputs:
112+ testClassesDirs = output.classesDirs
113+
114+ useJUnitPlatform()
115+ testLogging {
116+ events(" passed" , " skipped" , " failed" )
117+ showStandardStreams = true
118+ showStackTraces = true
119+ showExceptions = true
120+ exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat .FULL
121+ }
150122 }
151123 }
152124 }
153125 }
154126 }
155- }
156127
128+ dependencies {
129+ dokkaPlugin(project(" :dokka-aws" ))
130+ }
157131
158- // fixes outgoing variant metadata: https://github.com/awslabs/smithy-kotlin/issues/258
159- fun Project.setOutgoingVariantMetadata () {
160- tasks.withType<JavaCompile >() {
161- val javaVersion = JavaVersion .VERSION_1_8 .toString()
162- sourceCompatibility = javaVersion
163- targetCompatibility = javaVersion
132+ tasks.withType< org.jetbrains.kotlin.gradle.tasks.KotlinCompile > {
133+ kotlinOptions {
134+ allWarningsAsErrors = false // FIXME Tons of errors occur in generated code
135+ jvmTarget = " 1.8" // fixes outgoing variant metadata: https://github.com/awslabs/smithy-kotlin/issues/258
136+ }
164137 }
138+
139+ apply (from = rootProject.file(" gradle/publish.gradle" ))
165140}
0 commit comments