Skip to content

Commit

Permalink
[#31] Configure multiplatform build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ccjernigan committed Apr 21, 2022
1 parent 3f24445 commit 4cf04f7
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 30 deletions.
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3f24445329869fd19b9ea3fe72d97aefa768ea0a
25 changes: 25 additions & 0 deletions build-conventions/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
plugins {
`kotlin-dsl`
}

buildscript {
dependencyLocking {
lockAllConfigurations()
}
}

dependencyLocking {
lockAllConfigurations()
}

// Per conversation in the KotlinLang Slack, Gradle uses Java 8 compatibility internally
// for all build scripts.
// https://kotlinlang.slack.com/archives/C19FD9681/p1636632870122900?thread_ts=1636572288.117000&cid=C19FD9681
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:${libs.versions.kotlin.get()}")
}
13 changes: 13 additions & 0 deletions build-conventions/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@Suppress("UnstableApiUsage")
dependencyResolutionManagement {
repositories {
mavenCentral()
}
dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import org.gradle.jvm.toolchain.JavaToolchainSpec

pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
extensions.findByType<org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension>()?.apply {
jvmToolchain {
val javaVersion = JavaVersion.toVersion(project.property("JVM_TOOLCHAIN").toString())
val javaLanguageVersion = JavaLanguageVersion.of(javaVersion.majorVersion)
(this as JavaToolchainSpec).languageVersion.set(javaLanguageVersion)
}

targets.matching { it.platformType.name == "jvm" }.all {
(this as org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget).apply {
val javaTargetVersion = project.property("JVM_TARGET").toString()

compilations.all {
kotlinOptions {
jvmTarget = javaTargetVersion
}
}
}
}

targets.all {
compilations.all {
kotlinOptions {
allWarningsAsErrors = project.property("BIP39_IS_TREAT_WARNINGS_AS_ERRORS").toString().toBoolean()
freeCompilerArgs = freeCompilerArgs + "-opt-in=kotlin.RequiresOptIn"
}
}
}
}
}
5 changes: 5 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ org.gradle.caching=true
org.gradle.parallel=true
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m

BIP39_IS_TREAT_WARNINGS_AS_ERRORS=false

JVM_TOOLCHAIN=17
JVM_TARGET=1.8

# Publishing : Required
GROUP=cash.z.ecc.android
POM_ARTIFACT_ID=kotlin-bip39
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ moshi-core = { module = "com.squareup.moshi:moshi", version.ref = "moshi" }
moshi-kotlin = { module = "com.squareup.moshi:moshi-kotlin", version.ref = "moshi" }

[plugins]
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
dokka = "org.jetbrains.dokka:1.6.20"
versions = "com.github.ben-manes.versions:0.42.0"
publish = "com.vanniktech.maven.publish:0.18.0"
53 changes: 24 additions & 29 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,32 @@ plugins {
group = project.property("GROUP").toString()
version = project.property("VERSION_NAME").toString()

sourceSets {
main {
java {
setSrcDirs(listOf("src/jvmMain/kotlin"))
kotlin {
jvm()
sourceSets {
val commonMain by getting {
dependencies {
}
}
}

test {
java {
setSrcDirs(listOf("src/jvmTest/kotlin", "src/jvmTest/resources"))
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val jvmMain by getting {
dependencies {
}
}
val jvmTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(libs.kotest.runner)
implementation(libs.kotest.assertion)
implementation(libs.kotest.property)
implementation(libs.moshi.core)
implementation(libs.moshi.kotlin)
}
}
}
}

kotlin {
jvmToolchain {
// This should be set lower for Android, although there's no compatible JVM for Apple Silicon
(this as JavaToolchainSpec).languageVersion.set(JavaLanguageVersion.of(11))
}
}

dependencies {
// Tests
testImplementation(kotlin("test"))
testImplementation(libs.kotest.runner)
testImplementation(libs.kotest.assertion)
testImplementation(libs.kotest.property)
testImplementation(libs.moshi.core)
testImplementation(libs.moshi.kotlin)
}

tasks.withType<Test> {
useJUnitPlatform()
}
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ dependencyResolutionManagement {

rootProject.name = "kotlin-bip39"
include(":lib")

includeBuild("build-conventions")

0 comments on commit 4cf04f7

Please sign in to comment.