Skip to content

Commit b971b1e

Browse files
marijarinm.zharinovamfvanek
authored
Add Kotlin app with Spring Boot 3 and coroutines (#264)
* add build files for kotlin module * add kotlin classes and fix adding detekt to java build * классы переписаны нужен рефакторинг * дописаны тесты, отдельный плагин для общих настроек * kafka initializer * fix kafka container import * info level for testcontainers * exclude detect-formatting as it causes initialization error in tests * fix logs in kotlin app * add application kt exclusion from test report * exclude loggers from test coverage verification * fix build files * Moved dependencies to the version catalog * Added detekt * Fix * добавлены правила для детекта * пустая строка * Increase code coverage --------- Co-authored-by: m.zharinova <[email protected]> Co-authored-by: Ivan Vakhrushev <[email protected]>
1 parent 8edd8a1 commit b971b1e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1966
-95
lines changed

.editorconfig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ max_line_length = 199
88
tab_width = 4
99
ij_continuation_indent_size = 4
1010

11-
[*.java]
11+
[*.{java,kt}]
1212
ij_java_imports_layout = *,|,java.**,javax.**,|,$*
1313
ij_java_align_multiline_parameters = true
1414
ij_java_blank_lines_after_class_header = 1
@@ -30,8 +30,8 @@ ij_java_keep_simple_blocks_in_one_line = true
3030
ij_java_keep_simple_classes_in_one_line = false
3131
ij_java_keep_simple_lambdas_in_one_line = true
3232
ij_java_keep_simple_methods_in_one_line = true
33-
ij_java_names_count_to_use_import_on_demand = 101
34-
ij_java_class_count_to_use_import_on_demand = 101
33+
ij_java_names_count_to_use_import_on_demand = 201
34+
ij_java_class_count_to_use_import_on_demand = 201
3535
ij_java_packages_to_use_import_on_demand = java.awt.*, javax.swing.*
3636
ij_java_prefer_longer_names = true
3737
ij_java_space_after_closing_angle_bracket_in_type_argument = false

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description = "Experiments with Java"
99

1010
allprojects {
1111
group = "io.github.mfvanek"
12-
version = "0.3.3"
12+
version = "0.4.0"
1313

1414
repositories {
1515
mavenLocal()

buildSrc/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ dependencies {
1414
implementation("de.thetaphi:forbiddenapis:3.9")
1515
implementation("com.github.spotbugs.snom:spotbugs-gradle-plugin:6.1.7")
1616
implementation("org.gradle:test-retry-gradle-plugin:1.6.2")
17+
val kotlinVersion = "2.0.21"
18+
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
19+
implementation("org.jetbrains.kotlin:kotlin-allopen:$kotlinVersion")
20+
implementation(libs.detekt)
1721
}

buildSrc/settings.gradle.kts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
rootProject.name = "sb-ot-demo-conventions"
2+
3+
dependencyResolutionManagement {
4+
versionCatalogs {
5+
create("libs") {
6+
from(files("../gradle/libs.versions.toml"))
7+
}
8+
}
9+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
plugins {
2+
id("java")
3+
id("jacoco")
4+
}
5+
tasks {
6+
jacocoTestCoverageVerification {
7+
dependsOn(jacocoTestReport)
8+
violationRules {
9+
rule {
10+
limit {
11+
counter = "CLASS"
12+
value = "MISSEDCOUNT"
13+
maximum = "0.0".toBigDecimal()
14+
}
15+
}
16+
rule {
17+
limit {
18+
counter = "METHOD"
19+
value = "MISSEDCOUNT"
20+
maximum = "2.0".toBigDecimal()
21+
}
22+
}
23+
rule {
24+
limit {
25+
counter = "LINE"
26+
value = "MISSEDCOUNT"
27+
maximum = "7.0".toBigDecimal()
28+
}
29+
}
30+
rule {
31+
limit {
32+
counter = "INSTRUCTION"
33+
value = "COVEREDRATIO"
34+
minimum = "0.93".toBigDecimal()
35+
}
36+
}
37+
rule {
38+
limit {
39+
counter = "BRANCH"
40+
value = "COVEREDRATIO"
41+
minimum = "0.66".toBigDecimal()
42+
}
43+
}
44+
}
45+
}
46+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2020-2025. Ivan Vakhrushev and others.
3+
* https://github.com/mfvanek/spring-boot-open-telemetry-demo
4+
*
5+
* Licensed under the Apache License 2.0
6+
*/
7+
8+
plugins {
9+
id("java")
10+
id("jacoco")
11+
id("com.google.osdetector")
12+
id("org.gradle.test-retry")
13+
}
14+
15+
dependencies {
16+
testImplementation("org.assertj:assertj-core")
17+
testImplementation("org.junit.jupiter:junit-jupiter-api")
18+
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
19+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
20+
// https://github.com/netty/netty/issues/11020
21+
if (osdetector.arch == "aarch_64") {
22+
testImplementation("io.netty:netty-all:4.1.104.Final")
23+
}
24+
}
25+
26+
java {
27+
sourceCompatibility = JavaVersion.VERSION_21
28+
targetCompatibility = JavaVersion.VERSION_21
29+
withJavadocJar()
30+
withSourcesJar()
31+
}
32+
33+
tasks {
34+
withType<JavaCompile>().configureEach {
35+
options.compilerArgs.add("-parameters")
36+
options.compilerArgs.add("--should-stop=ifError=FLOW")
37+
}
38+
39+
test {
40+
useJUnitPlatform()
41+
42+
finalizedBy(jacocoTestReport, jacocoTestCoverageVerification)
43+
maxParallelForks = 1
44+
45+
retry {
46+
maxRetries.set(2)
47+
maxFailures.set(5)
48+
failOnPassedAfterRetry.set(false)
49+
}
50+
}
51+
52+
jacocoTestReport {
53+
dependsOn(test)
54+
reports {
55+
xml.required.set(true)
56+
html.required.set(true)
57+
}
58+
}
59+
60+
check {
61+
dependsOn(jacocoTestCoverageVerification)
62+
}
63+
}

buildSrc/src/main/kotlin/sb-ot-demo.java-conventions.gradle.kts

Lines changed: 2 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ plugins {
1919
id("net.ltgt.errorprone")
2020
id("com.google.osdetector")
2121
id("org.gradle.test-retry")
22+
id("sb-ot-demo.java-compile")
23+
id("sb-ot-demo.jacoco-rules")
2224
}
2325

2426
dependencies {
@@ -43,16 +45,6 @@ dependencies {
4345
spotbugsPlugins("com.mebigfatguy.sb-contrib:sb-contrib:7.6.9")
4446
}
4547

46-
java {
47-
toolchain {
48-
languageVersion = JavaLanguageVersion.of(17)
49-
}
50-
}
51-
52-
jacoco {
53-
toolVersion = "0.8.12"
54-
}
55-
5648
checkstyle {
5749
toolVersion = "10.21.1"
5850
configFile = file("${rootDir}/config/checkstyle/checkstyle.xml")
@@ -84,77 +76,13 @@ tasks.withType<SpotBugsTask>().configureEach {
8476

8577
tasks {
8678
withType<JavaCompile>().configureEach {
87-
options.compilerArgs.add("-parameters")
88-
options.compilerArgs.add("--should-stop=ifError=FLOW")
8979
options.errorprone {
9080
disableWarningsInGeneratedCode.set(true)
9181
disable("Slf4jLoggerShouldBeNonStatic")
9282
}
9383
}
9484

9585
test {
96-
useJUnitPlatform()
9786
dependsOn(checkstyleMain, checkstyleTest, pmdMain, pmdTest, spotbugsMain, spotbugsTest)
98-
finalizedBy(jacocoTestReport, jacocoTestCoverageVerification)
99-
maxParallelForks = 1
100-
101-
retry {
102-
maxRetries.set(2)
103-
maxFailures.set(5)
104-
failOnPassedAfterRetry.set(false)
105-
}
106-
}
107-
108-
jacocoTestCoverageVerification {
109-
dependsOn(jacocoTestReport)
110-
violationRules {
111-
rule {
112-
limit {
113-
counter = "CLASS"
114-
value = "MISSEDCOUNT"
115-
maximum = "0.0".toBigDecimal()
116-
}
117-
}
118-
rule {
119-
limit {
120-
counter = "METHOD"
121-
value = "MISSEDCOUNT"
122-
maximum = "2.0".toBigDecimal()
123-
}
124-
}
125-
rule {
126-
limit {
127-
counter = "LINE"
128-
value = "MISSEDCOUNT"
129-
maximum = "7.0".toBigDecimal()
130-
}
131-
}
132-
rule {
133-
limit {
134-
counter = "INSTRUCTION"
135-
value = "COVEREDRATIO"
136-
minimum = "0.93".toBigDecimal()
137-
}
138-
}
139-
rule {
140-
limit {
141-
counter = "BRANCH"
142-
value = "COVEREDRATIO"
143-
minimum = "0.66".toBigDecimal()
144-
}
145-
}
146-
}
147-
}
148-
149-
jacocoTestReport {
150-
dependsOn(test)
151-
reports {
152-
xml.required.set(true)
153-
html.required.set(true)
154-
}
155-
}
156-
157-
check {
158-
dependsOn(jacocoTestCoverageVerification)
15987
}
16088
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2020-2025. Ivan Vakhrushev and others.
3+
* https://github.com/mfvanek/spring-boot-open-telemetry-demo
4+
*
5+
* Licensed under the Apache License 2.0
6+
*/
7+
8+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
9+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
10+
11+
plugins {
12+
id("java")
13+
id("jacoco")
14+
id("org.jetbrains.kotlin.jvm")
15+
id("org.jetbrains.kotlin.plugin.spring")
16+
id("io.gitlab.arturbosch.detekt")
17+
id("sb-ot-demo.forbidden-apis")
18+
id("sb-ot-demo.java-compile")
19+
}
20+
21+
private val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
22+
23+
dependencies {
24+
implementation("org.jetbrains.kotlin:kotlin-reflect")
25+
libs.findLibrary("detekt-formatting").ifPresent {
26+
detektPlugins(it)
27+
}
28+
libs.findLibrary("detekt-libraries").ifPresent {
29+
detektPlugins(it)
30+
}
31+
}
32+
33+
tasks.withType<KotlinCompile> {
34+
compilerOptions {
35+
freeCompilerArgs.add("-Xjsr305=strict")
36+
jvmTarget = JvmTarget.JVM_21
37+
}
38+
}
39+
40+
detekt {
41+
toolVersion = libs.findVersion("detekt").get().requiredVersion
42+
config.setFrom(file("${rootDir}/config/detekt/detekt.yml"))
43+
buildUponDefaultConfig = true
44+
autoCorrect = true
45+
}

0 commit comments

Comments
 (0)