Skip to content

Commit 7628ae8

Browse files
committed
Check Kotlin code using Detekt
Closes gh-45583
1 parent e331846 commit 7628ae8

File tree

357 files changed

+911
-491
lines changed

Some content is hidden

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

357 files changed

+911
-491
lines changed

buildSrc/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ dependencies {
3636
implementation("commons-codec:commons-codec:${commonsCodecVersion}")
3737
implementation("de.undercouch.download:de.undercouch.download.gradle.plugin:5.5.0")
3838
implementation("dev.adamko.dokkatoo:dokkatoo-plugin:2.3.1")
39+
implementation("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.23.8")
3940
implementation("io.spring.gradle.antora:spring-antora-plugin:0.0.1")
4041
implementation("io.spring.javaformat:spring-javaformat-gradle-plugin:${javaFormatVersion}")
4142
implementation("io.spring.nohttp:nohttp-gradle:0.0.11")

buildSrc/src/main/java/org/springframework/boot/build/KotlinConventions.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,6 +22,9 @@
2222

2323
import dev.adamko.dokkatoo.DokkatooExtension;
2424
import dev.adamko.dokkatoo.formats.DokkatooHtmlPlugin;
25+
import io.gitlab.arturbosch.detekt.Detekt;
26+
import io.gitlab.arturbosch.detekt.DetektPlugin;
27+
import io.gitlab.arturbosch.detekt.extensions.DetektExtension;
2528
import org.gradle.api.Project;
2629
import org.gradle.api.tasks.SourceSet;
2730
import org.gradle.api.tasks.SourceSetContainer;
@@ -40,6 +43,7 @@
4043
* <li>Treat all warnings as errors
4144
* <li>Suppress version warnings
4245
* </ul>
46+
* <li>Detekt plugin is applied to perform static analysis of Kotlin code
4347
* </ul>
4448
*
4549
* <p/>
@@ -48,18 +52,23 @@
4852
*/
4953
class KotlinConventions {
5054

55+
private static final String JVM_TARGET = "17";
56+
57+
private static final String KOTLIN_VERSION = "1.7";
58+
5159
void apply(Project project) {
5260
project.getPlugins().withId("org.jetbrains.kotlin.jvm", (plugin) -> {
5361
project.getTasks().withType(KotlinCompile.class, this::configure);
5462
project.getPlugins().withType(DokkatooHtmlPlugin.class, (dokkatooPlugin) -> configureDokkatoo(project));
63+
configureDetekt(project);
5564
});
5665
}
5766

5867
private void configure(KotlinCompile compile) {
5968
KotlinJvmOptions kotlinOptions = compile.getKotlinOptions();
60-
kotlinOptions.setApiVersion("1.7");
61-
kotlinOptions.setLanguageVersion("1.7");
62-
kotlinOptions.setJvmTarget("17");
69+
kotlinOptions.setApiVersion(KOTLIN_VERSION);
70+
kotlinOptions.setLanguageVersion(KOTLIN_VERSION);
71+
kotlinOptions.setJvmTarget(JVM_TARGET);
6372
kotlinOptions.setAllWarningsAsErrors(true);
6473
List<String> freeCompilerArgs = new ArrayList<>(kotlinOptions.getFreeCompilerArgs());
6574
freeCompilerArgs.add("-Xsuppress-version-warnings");
@@ -91,4 +100,11 @@ private void configureDokkatoo(Project project) {
91100
});
92101
}
93102

103+
private void configureDetekt(Project project) {
104+
project.getPlugins().apply(DetektPlugin.class);
105+
DetektExtension detekt = project.getExtensions().getByType(DetektExtension.class);
106+
detekt.getConfig().setFrom(project.getRootProject().file("src/detekt/config.yml"));
107+
project.getTasks().withType(Detekt.class).configureEach((task) -> task.setJvmTarget(JVM_TARGET));
108+
}
109+
94110
}

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/cloudfoundry/customcontextpath/MyCloudFoundryConfiguration.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -69,4 +69,5 @@ class MyCloudFoundryConfiguration {
6969
context.addServlet("cloudfoundry", servlet).addMapping("/*")
7070
}
7171
}
72-
}
72+
}
73+

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/cloudfoundry/customcontextpath/MyReactiveCloudFoundryConfiguration.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -51,3 +51,4 @@ class MyReactiveCloudFoundryConfiguration {
5151
}
5252
}
5353
}
54+

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/endpoints/health/reactivehealthindicators/MyReactiveHealthIndicator.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,4 +37,5 @@ class MyReactiveHealthIndicator : ReactiveHealthIndicator {
3737
return /**/ null
3838
}
3939

40-
}
40+
}
41+

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/endpoints/health/writingcustomhealthindicators/MyHealthIndicator.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,4 +36,5 @@ class MyHealthIndicator : HealthIndicator {
3636
return /**/ 0
3737
}
3838

39-
}
39+
}
40+

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/endpoints/implementingcustom/CustomData.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,4 +16,5 @@
1616

1717
package org.springframework.boot.docs.actuator.endpoints.implementingcustom
1818

19-
class CustomData(val name: String, val counter: Int)
19+
class CustomData(val name: String, val counter: Int)
20+

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/endpoints/implementingcustom/MyEndpoint.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,4 +37,5 @@ class MyEndpoint {
3737
// injects "test" and 42
3838
}
3939
// end::write[]
40-
}
40+
}
41+

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/endpoints/info/writingcustominfocontributors/MyInfoContributor.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,4 +28,5 @@ class MyInfoContributor : InfoContributor {
2828
builder.withDetail("example", Collections.singletonMap("key", "value"))
2929
}
3030

31-
}
31+
}
32+

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/endpoints/security/exposeall/MySecurityConfiguration.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,3 +34,4 @@ class MySecurityConfiguration {
3434
}
3535

3636
}
37+

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/endpoints/security/typical/MySecurityConfiguration.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,3 +36,4 @@ class MySecurityConfiguration {
3636
}
3737

3838
}
39+

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/metrics/customizing/MyMetricsFilterConfiguration.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,4 +28,5 @@ class MyMetricsFilterConfiguration {
2828
return MeterFilter.renameTag("com.example", "mytag.region", "mytag.area")
2929
}
3030

31-
}
31+
}
32+

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/metrics/export/graphite/MyGraphiteConfiguration.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,4 +36,5 @@ class MyGraphiteConfiguration {
3636
return /**/ HierarchicalNameMapper.DEFAULT.toHierarchicalName(id, convention)
3737
}
3838

39-
}
39+
}
40+

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/metrics/export/jmx/MyJmxConfiguration.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,4 +37,5 @@ class MyJmxConfiguration {
3737
return /**/ HierarchicalNameMapper.DEFAULT.toHierarchicalName(id, convention)
3838
}
3939

40-
}
40+
}
41+

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/metrics/gettingstarted/commontags/MyMeterRegistryConfiguration.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,4 +31,5 @@ class MyMeterRegistryConfiguration {
3131
}
3232
}
3333

34-
}
34+
}
35+

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/metrics/gettingstarted/specifictype/MyMeterRegistryConfiguration.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,4 +37,5 @@ class MyMeterRegistryConfiguration {
3737
return /**/ NamingConvention.snakeCase.name(name, type, baseUnit)
3838
}
3939

40-
}
40+
}
41+

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/metrics/registeringcustom/Dictionary.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,4 +27,5 @@ internal class Dictionary {
2727
}
2828
}
2929

30-
}
30+
}
31+

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/metrics/registeringcustom/MyBean.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,4 +30,5 @@ class MyBean(registry: MeterRegistry) {
3030
registry.gauge("dictionary.size", Tags.empty(), dictionary.words.size)
3131
}
3232

33-
}
33+
}
34+

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/metrics/registeringcustom/MyMeterBinderConfiguration.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,4 +29,5 @@ class MyMeterBinderConfiguration {
2929
}
3030
}
3131

32-
}
32+
}
33+

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/metrics/registeringcustom/Queue.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,4 +22,5 @@ class Queue {
2222
return 5
2323
}
2424

25-
}
25+
}
26+

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/metrics/supported/mongodb/command/CustomCommandTagsProvider.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,3 +27,4 @@ class CustomCommandTagsProvider : MongoCommandTagsProvider {
2727
}
2828

2929
}
30+

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/metrics/supported/mongodb/command/MyCommandTagsProviderConfiguration.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,3 +29,4 @@ class MyCommandTagsProviderConfiguration {
2929
}
3030

3131
}
32+

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/metrics/supported/mongodb/connectionpool/CustomConnectionPoolTagsProvider.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,3 +27,4 @@ class CustomConnectionPoolTagsProvider : MongoConnectionPoolTagsProvider {
2727
}
2828

2929
}
30+

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/actuator/metrics/supported/mongodb/connectionpool/MyConnectionPoolTagsProviderConfiguration.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,3 +29,4 @@ class MyConnectionPoolTagsProviderConfiguration {
2929
}
3030

3131
}
32+

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/buildtoolplugins/otherbuildsystems/examplerepackageimplementation/MyBuildTool.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,4 +46,5 @@ class MyBuildTool {
4646
return /**/ null
4747
}
4848

49-
}
49+
}
50+

0 commit comments

Comments
 (0)