Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Introduce basic Kotlin MPP project layout #77

Merged
merged 6 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 45 additions & 30 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,27 @@

*/

import com.charleskorn.kaml.build.Versions
import com.charleskorn.kaml.build.configureAssemble
import com.charleskorn.kaml.build.configureJacoco
import com.charleskorn.kaml.build.configurePublishing
import com.charleskorn.kaml.build.configureSpotless
import com.charleskorn.kaml.build.configureTesting
import com.charleskorn.kaml.build.configureVersioning
import com.charleskorn.kaml.build.configureWrapper
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

buildscript {
repositories {
jcenter()
}

dependencies {
classpath(kotlin("serialization", version = "1.4.10"))
}
}

plugins {
kotlin("jvm") version "1.4.10"

apply { id("com.github.ben-manes.versions") version "0.36.0" }
kotlin("multiplatform") version "1.4.10"
id("org.jetbrains.kotlin.plugin.serialization") version "1.4.10"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know I wasn't using it before, but it might be good to switch to the kotlin("plugin.serialization") method here as well, as described in the kotlinx.serialization readme.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Of course it should.

id("com.github.ben-manes.versions") version "0.36.0"
}

apply(plugin = "kotlinx-serialization")

group = "com.charleskorn.kaml"

repositories {
Expand All @@ -51,28 +45,49 @@ repositories {
maven(url = "https://kotlin.bintray.com/kotlinx")
}

dependencies {
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))

implementation(kotlin("stdlib-jdk8"))
implementation(group = "org.snakeyaml", name = "snakeyaml-engine", version = "2.2.1")
implementation(group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-core", version = "1.0.1")

val spekVersion = "2.0.15"

testImplementation(group = "org.spekframework.spek2", name = "spek-dsl-jvm", version = spekVersion)
testImplementation(group = "ch.tutteli.atrium", name = "atrium-fluent-en_GB", version = "0.15.0")

testRuntimeOnly(group = "org.spekframework.spek2", name = "spek-runner-junit5", version = spekVersion)
}

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.freeCompilerArgs = listOf("-Xuse-experimental=kotlin.RequiresOptIn")
}

kotlin {
explicitApi()

jvm {
withJava()
compilations.all {
kotlinOptions {
jvmTarget = "1.8"
}
}
}

sourceSets {
all {
languageSettings.useExperimentalAnnotation("kotlin.RequiresOptIn")
}
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:${Versions.serialization}")
}
}
val commonTest by getting {
dependencies {
implementation("org.spekframework.spek2:spek-dsl-metadata:${Versions.spek}")
implementation("ch.tutteli.atrium:atrium-fluent-en_GB-common:${Versions.atrium}")
}
}
val jvmMain by getting {
dependencies {
implementation(project.dependencies.platform("org.jetbrains.kotlin:kotlin-bom"))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be applied to kotlinMain?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't know what's kotlinMain. The source sets are named like the targets (i.e. js, jvm, common, linuxX64, …) where there is no kotlin target. As per this forum post it seems that the platform is nothing that's even supposed to be used in Kotlin/MPP (maybe yet). So this seems to be the currently most viable workaround.

implementation(kotlin("stdlib-jdk8"))
implementation("org.snakeyaml:snakeyaml-engine:${Versions.snakeYaml}")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:${Versions.serialization}")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be applied again if it's already in commonMain?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another good catch. It does not. jvmMain depends on commonMain automatically.

}
}
val jvmTest by getting {
dependencies {
implementation("org.spekframework.spek2:spek-dsl-jvm:${Versions.spek}")
implementation("ch.tutteli.atrium:atrium-fluent-en_GB:${Versions.atrium}")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing again - does this need to be here if it's also in commonTest? (I haven't worked extensively with a MPP project before, so forgive me if this is a dumb question 😄)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite the opposite. jvmTest does not depend on commonTest and it would not make much sense as the JVM implementations of the frameworks are usually more powerful and you don't need conflicting definitions in your classpath. I'd leave it here as it does no harm (version is centralized elsewhere…).

runtimeOnly("org.spekframework.spek2:spek-runner-junit5:${Versions.spek}")
}
}
}
}

configureAssemble()
Expand Down
26 changes: 26 additions & 0 deletions buildSrc/src/main/kotlin/com/charleskorn/kaml/build/Versions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*

Copyright 2018-2020 Charles Korn.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

*/

package com.charleskorn.kaml.build

object Versions {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Renovate support updating versions when configured like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know about Renovate (never heard of it) but you apply the versions plugin which I'm also using in a number of projects configured this way. That plugin works with such a versions object.

const val atrium = "0.15.0"
const val serialization = "1.0.1"
const val snakeYaml = "2.2.1"
const val spek = "2.0.15"
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package com.charleskorn.kaml

import ch.tutteli.atrium.api.fluent.en_GB.feature
import ch.tutteli.atrium.creating.Expect
import kotlin.jvm.JvmName

fun <T : YamlException> Expect<T>.path(assertionCreator: Expect<YamlPath>.() -> Unit) {
feature(YamlException::path).addAssertionsCreatedBy(assertionCreator)
Expand Down