Skip to content

Commit 9cc529e

Browse files
committed
Add test sample for working with Kotlin
1 parent b5ddb2d commit 9cc529e

File tree

20 files changed

+223
-4
lines changed

20 files changed

+223
-4
lines changed

samples/basic/build-logic/src/main/kotlin/org.my.gradle.java-module.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ group = "org.my"
66

77
tasks.test {
88
useJUnitPlatform()
9+
jvmArgs("-Dorg.slf4j.simpleLogger.defaultLogLevel=error")
910
}
1011

1112
dependencies {

samples/basic/build.out

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
> Task :app:compileTestJava
1414
> Task :app:processTestResources NO-SOURCE
1515
> Task :app:testClasses
16-
[Test worker] INFO org.gradle.api.internal.tasks.testing.worker.TestWorker - Gradle Test Executor 1 started executing tests.
17-
[Test worker] INFO org.gradle.api.internal.tasks.testing.worker.TestWorker - Gradle Test Executor 1 finished executing tests.
1816
> Task :app:test
1917
> Task :app:check
2018
> Task :app:build

samples/configuration-cache/build-logic/src/main/kotlin/org.my.gradle.java-module.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ group = "org.my"
66

77
tasks.test {
88
useJUnitPlatform()
9+
jvmArgs("-Dorg.slf4j.simpleLogger.defaultLogLevel=error")
910
}
1011

1112
dependencies {

samples/configuration-cache/build.out

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
> Task :app:compileTestJava
1515
> Task :app:processTestResources NO-SOURCE
1616
> Task :app:testClasses
17-
[Test worker] INFO org.gradle.api.internal.tasks.testing.worker.TestWorker - Gradle Test Executor 2 started executing tests.
18-
[Test worker] INFO org.gradle.api.internal.tasks.testing.worker.TestWorker - Gradle Test Executor 2 finished executing tests.
1917
> Task :app:test
2018
> Task :app:check
2119
> Task :app:build
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
plugins {
2+
id("org.my.gradle.kotlin-java-module")
3+
id("application")
4+
}
5+
6+
application {
7+
applicationDefaultJvmArgs = listOf("-ea")
8+
mainClass.set("org.my.app.AppKt")
9+
mainModule.set("org.my.app")
10+
}
11+
12+
dependencies {
13+
runtimeOnly(javaModuleDependencies.gav("org.slf4j.simple"))
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module org.my.app {
2+
requires org.slf4j;
3+
requires org.my.lib;
4+
requires static org.apache.xmlbeans;
5+
6+
requires kotlin.stdlib;
7+
8+
exports org.my.app;
9+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.my.app
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper
4+
import org.apache.xmlbeans.impl.tool.XMLBean
5+
import org.slf4j.spi.LoggerFactoryBinder
6+
7+
fun main() {
8+
App.doWork()
9+
}
10+
11+
object App {
12+
fun doWork(): Boolean {
13+
val om = ObjectMapper()
14+
if (!om.canSerialize(LoggerFactoryBinder::class.java)) {
15+
throw RuntimeException("Boom!")
16+
}
17+
println(App::class.java.module.name)
18+
try {
19+
XMLBean()
20+
throw RuntimeException("Boom!")
21+
} catch (e: NoClassDefFoundError) {
22+
// This is expected at runtime!
23+
}
24+
return true
25+
}
26+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
open module org.my.app.test {
2+
requires org.my.app;
3+
requires org.junit.jupiter.api;
4+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.my.app.test
2+
3+
import org.junit.jupiter.api.Test
4+
import org.my.app.App
5+
6+
import org.junit.jupiter.api.Assertions.assertTrue
7+
8+
class AppTest {
9+
10+
@Test
11+
fun appDoesNotExplode() {
12+
assertTrue(App.doWork());
13+
}
14+
15+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
dependencies {
6+
implementation("de.jjohannes.gradle:java-module-dependencies:0.6")
7+
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10")
8+
}

0 commit comments

Comments
 (0)