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 8fc703a
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 31 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()}")
}
45 changes: 45 additions & 0 deletions build-conventions/buildscript-gradle.lockfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This is a Gradle generated file for dependency locking.
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.github.gundy:semver4j:0.16.4=classpath
com.google.code.findbugs:jsr305:3.0.2=classpath
com.google.code.gson:gson:2.8.6=classpath
com.google.errorprone:error_prone_annotations:2.3.4=classpath
com.google.guava:failureaccess:1.0.1=classpath
com.google.guava:guava:29.0-jre=classpath
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=classpath
com.google.j2objc:j2objc-annotations:1.3=classpath
de.undercouch:gradle-download-task:4.1.1=classpath
org.checkerframework:checker-qual:2.11.1=classpath
org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:2.1.7=classpath
org.gradle.kotlin:gradle-kotlin-dsl-plugins:2.1.7=classpath
org.jetbrains.intellij.deps:trove4j:1.0.20181211=classpath
org.jetbrains.kotlin:kotlin-android-extensions:1.5.31=classpath
org.jetbrains.kotlin:kotlin-annotation-processing-gradle:1.5.31=classpath
org.jetbrains.kotlin:kotlin-build-common:1.5.31=classpath
org.jetbrains.kotlin:kotlin-compiler-embeddable:1.5.31=classpath
org.jetbrains.kotlin:kotlin-compiler-runner:1.5.31=classpath
org.jetbrains.kotlin:kotlin-daemon-client:1.5.31=classpath
org.jetbrains.kotlin:kotlin-daemon-embeddable:1.5.31=classpath
org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.5.31=classpath
org.jetbrains.kotlin:kotlin-gradle-plugin-model:1.5.31=classpath
org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31=classpath
org.jetbrains.kotlin:kotlin-klib-commonizer-api:1.5.31=classpath
org.jetbrains.kotlin:kotlin-native-utils:1.5.31=classpath
org.jetbrains.kotlin:kotlin-project-model:1.5.31=classpath
org.jetbrains.kotlin:kotlin-sam-with-receiver:1.5.31=classpath
org.jetbrains.kotlin:kotlin-scripting-common:1.5.31=classpath
org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:1.5.31=classpath
org.jetbrains.kotlin:kotlin-scripting-compiler-impl-embeddable:1.5.31=classpath
org.jetbrains.kotlin:kotlin-scripting-jvm:1.5.31=classpath
org.jetbrains.kotlin:kotlin-stdlib-common:1.5.31=classpath
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.31=classpath
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.31=classpath
org.jetbrains.kotlin:kotlin-stdlib:1.5.31=classpath
org.jetbrains.kotlin:kotlin-tooling-metadata:1.5.31=classpath
org.jetbrains.kotlin:kotlin-util-io:1.5.31=classpath
org.jetbrains.kotlin:kotlin-util-klib:1.5.31=classpath
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.0=classpath
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0=classpath
org.jetbrains:annotations:13.0=classpath
empty=
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"
}
}
}
}
}
7 changes: 7 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ org.gradle.caching=true
org.gradle.parallel=true
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m

kotlin.mpp.stability.nowarn=true

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"
55 changes: 25 additions & 30 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
alias(libs.plugins.kotlin)
id("org.jetbrains.kotlin.multiplatform") version(libs.versions.kotlin.get())
id("java-library")
alias(libs.plugins.dokka)
alias(libs.plugins.publish)
Expand All @@ -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()
}
4 changes: 4 additions & 0 deletions settings-gradle.lockfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This is a Gradle generated file for dependency locking.
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
empty=incomingCatalogForLibs0
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 8fc703a

Please sign in to comment.