-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add a test for kotlin multiplatform
- Loading branch information
Showing
10 changed files
with
223 additions
and
0 deletions.
There are no files selected for viewing
146 changes: 146 additions & 0 deletions
146
src/test/resources/org/danilopianini/gradle/test/ktmultiplatform/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
@file:Suppress("UnstableApiUsage") | ||
|
||
import org.danilopianini.gradle.mavencentral.JavadocJar | ||
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget | ||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly | ||
|
||
@Suppress("DSL_SCOPE_VIOLATION") | ||
plugins { | ||
alias(libs.plugins.kotlin.multiplatform) | ||
alias(libs.plugins.dokka) | ||
alias(libs.plugins.gitSemVer) | ||
alias(libs.plugins.kotlin.qa) | ||
alias(libs.plugins.multiJvmTesting) | ||
alias(libs.plugins.taskTree) | ||
id("org.danilopianini.publish-on-central") | ||
} | ||
|
||
group = "org.danilopianini" | ||
|
||
repositories { | ||
google() | ||
mavenCentral() | ||
} | ||
|
||
kotlin { | ||
jvm { | ||
compilations.all { | ||
kotlinOptions.jvmTarget = "1.8" | ||
} | ||
testRuns["test"].executionTask.configure { | ||
useJUnitPlatform() | ||
} | ||
} | ||
js(IR) { | ||
browser() | ||
nodejs() | ||
binaries.library() | ||
} | ||
val hostOs = System.getProperty("os.name").trim().toLowerCaseAsciiOnly() | ||
val hostArch = System.getProperty("os.arch").trim().toLowerCaseAsciiOnly() | ||
val nativeTarget: (String, org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget.() -> Unit) -> KotlinTarget = | ||
when (hostOs to hostArch) { | ||
"linux" to "aarch64" -> ::linuxArm64 | ||
"linux" to "amd64" -> ::linuxX64 | ||
"linux" to "arm", "linux" to "arm32" -> ::linuxArm32Hfp | ||
"linux" to "mips", "linux" to "mips32" -> ::linuxMips32 | ||
"linux" to "mipsel", "linux" to "mips32el" -> ::linuxMipsel32 | ||
"mac os x" to "aarch64" -> ::macosArm64 | ||
"mac os x" to "amd64", "mac os x" to "x86_64" -> ::macosX64 | ||
"windows" to "amd64", "windows server 2022" to "amd64" -> ::mingwX64 | ||
"windows" to "x86" -> ::mingwX86 | ||
else -> throw GradleException("Host OS '$hostOs' with arch '$hostArch' is not supported in Kotlin/Native.") | ||
} | ||
nativeTarget("native") { | ||
binaries { | ||
sharedLib() | ||
staticLib() | ||
// Remove if it is not executable | ||
"main".let { executable -> | ||
executable { | ||
entryPoint = executable | ||
} | ||
// Enable wasm32 | ||
wasm32 { | ||
binaries { | ||
executable { | ||
entryPoint = executable | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
sourceSets { | ||
val commonMain by getting { | ||
dependencies { | ||
implementation(libs.kotlin.stdlib) | ||
} | ||
} | ||
val commonTest by getting { | ||
dependencies { | ||
implementation(libs.bundles.kotlin.testing.common) | ||
} | ||
} | ||
val jvmTest by getting { | ||
dependencies { | ||
implementation(libs.bundles.kotlin.testing.jvm) | ||
} | ||
} | ||
val nativeMain by getting { | ||
dependsOn(commonMain) | ||
} | ||
val nativeTest by getting { | ||
dependsOn(commonTest) | ||
} | ||
} | ||
targets.all { | ||
compilations.all { | ||
kotlinOptions { | ||
allWarningsAsErrors = true | ||
} | ||
} | ||
} | ||
} | ||
|
||
tasks.dokkaJavadoc { | ||
enabled = false | ||
} | ||
|
||
tasks.withType<JavadocJar>().configureEach { | ||
val dokka = tasks.dokkaHtml.get() | ||
dependsOn(dokka) | ||
from(dokka.outputDirectory) | ||
} | ||
|
||
signing { | ||
if (System.getenv("CI") == "true") { | ||
val signingKey: String? by project | ||
val signingPassword: String? by project | ||
useInMemoryPgpKeys(signingKey, signingPassword) | ||
} | ||
} | ||
|
||
publishOnCentral { | ||
projectLongName.set("Template for Kotlin Multiplatform Project") | ||
projectDescription.set("A template repository for Kotlin Multiplatform projects") | ||
repository("https://maven.pkg.github.com/danysk/${rootProject.name}".toLowerCase()) { | ||
user.set("DanySK") | ||
password.set(System.getenv("GITHUB_TOKEN")) | ||
} | ||
publishing { | ||
publications { | ||
withType<MavenPublication> { | ||
pom { | ||
developers { | ||
developer { | ||
name.set("Danilo Pianini") | ||
email.set("[email protected]") | ||
url.set("http://www.danilopianini.org/") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/test/resources/org/danilopianini/gradle/test/ktmultiplatform/gradle/libs.versions.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[versions] | ||
android-plugins = "7.0.0" | ||
kotest = "5.3.1" | ||
kotlin = "1.7.0" | ||
|
||
[libraries] | ||
kotest-assertions-core = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" } | ||
kotest-assertions-core-jvm = { module = "io.kotest:kotest-assertions-core-jvm", version.ref = "kotest" } | ||
kotest-framework-engine = { module = "io.kotest:kotest-framework-engine", version.ref = "kotest" } | ||
kotest-framework-datatest = { module = "io.kotest:kotest-framework-datatest", version.ref = "kotest" } | ||
kotest-runner-junit5-jvm = { module = "io.kotest:kotest-runner-junit5-jvm", version.ref = "kotest" } | ||
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-stdlib-reflect", version.ref = "kotlin" } | ||
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" } | ||
kotlin-stdlib-jdk8 = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin" } | ||
kotlin-test-common = { module = "org.jetbrains.kotlin:kotlin-test-common", version.ref = "kotlin" } | ||
kotlin-test-annotations-common = { module = "org.jetbrains.kotlin:kotlin-test-annotations-common", version.ref = "kotlin" } | ||
|
||
|
||
[bundles] | ||
kotlin-testing-common = [ | ||
"kotest-assertions-core", | ||
"kotest-framework-engine", | ||
"kotest-framework-datatest", | ||
"kotlin-test-common", | ||
"kotlin-test-annotations-common", | ||
] | ||
kotlin-testing-jvm = [ "kotest-assertions-core-jvm", "kotest-runner-junit5-jvm" ] | ||
|
||
[plugins] | ||
dokka = "org.jetbrains.dokka:1.6.21" | ||
gitSemVer = { id = "org.danilopianini.git-sensitive-semantic-versioning", version = "0.3.0" } | ||
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } | ||
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } | ||
kotlin-qa = "org.danilopianini.gradle-kotlin-qa:0.19.1" | ||
multiJvmTesting = "org.danilopianini.multi-jvm-test-plugin:0.4.3" | ||
npm-publish = "dev.petuska.npm.publish:3.0.0" | ||
taskTree = "com.dorongold.task-tree:2.1.0" |
3 changes: 3 additions & 0 deletions
3
...sources/org/danilopianini/gradle/test/ktmultiplatform/src/commonMain/kotlin/HelloWorld.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fun main() { | ||
println("Hello, ${Platform.name}!") | ||
} |
3 changes: 3 additions & 0 deletions
3
...resources/org/danilopianini/gradle/test/ktmultiplatform/src/commonMain/kotlin/Platform.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
expect object Platform { | ||
val name: String | ||
} |
10 changes: 10 additions & 0 deletions
10
...est/resources/org/danilopianini/gradle/test/ktmultiplatform/src/commonTest/kotlin/Test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import io.kotest.core.spec.style.StringSpec | ||
import io.kotest.matchers.shouldNotBe | ||
|
||
class Test : StringSpec( | ||
{ | ||
"a simple test" { | ||
true shouldNotBe false | ||
} | ||
} | ||
) |
3 changes: 3 additions & 0 deletions
3
...est/resources/org/danilopianini/gradle/test/ktmultiplatform/src/jsMain/kotlin/Platform.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
actual object Platform { | ||
actual val name = "JS" | ||
} |
3 changes: 3 additions & 0 deletions
3
...st/resources/org/danilopianini/gradle/test/ktmultiplatform/src/jvmMain/kotlin/Platform.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
actual object Platform { | ||
actual val name = "JVM" | ||
} |
3 changes: 3 additions & 0 deletions
3
...resources/org/danilopianini/gradle/test/ktmultiplatform/src/nativeMain/kotlin/Platform.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
actual object Platform { | ||
actual val name = "Native" | ||
} |
3 changes: 3 additions & 0 deletions
3
...resources/org/danilopianini/gradle/test/ktmultiplatform/src/wasm32Main/kotlin/Platform.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
actual object Platform { | ||
actual val name = "WASM" | ||
} |
12 changes: 12 additions & 0 deletions
12
src/test/resources/org/danilopianini/gradle/test/ktmultiplatform/test.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
tests: | ||
- description: "gradle should generate metadata files in kotlin-multiplatform projects" | ||
configuration: | ||
tasks: &tasks | ||
- 'generateMetadataFileForJavaMavenPublication' | ||
- 'generateMetadataFileForJvmPublication' | ||
- 'generateMetadataFileForKotlinMavenPublication' | ||
- 'generateMetadataFileForKotlinMultiplatformPublication' | ||
- 'generateMetadataFileForNativePublication' | ||
- 'generateMetadataFileForWasm32Publication' | ||
expectation: | ||
success: *tasks |