Skip to content

Commit fe0a197

Browse files
authored
Merge pull request #817 from simple-robot/apply-detekt
配置与应用detekt
2 parents 8f41a98 + 180a69d commit fe0a197

File tree

135 files changed

+2360
-1158
lines changed

Some content is hidden

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

135 files changed

+2360
-1158
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ indent_style = space
66
insert_final_newline = true
77
max_line_length = 120
88
tab_width = 4
9-
ij_continuation_indent_size = 8
9+
ij_continuation_indent_size = 4
1010
ij_formatter_off_tag = @formatter:off
1111
ij_formatter_on_tag = @formatter:on
1212
ij_formatter_tags_enabled = true

.github/workflows/publish-v4-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
uses: actions/upload-artifact@v4
4646
if: ${{ always() }}
4747
with:
48-
name: test-reports-${{ matrix.os }}
48+
name: test-reports-${{ runner.os }}
4949
path: '**/build/reports/tests'
5050
retention-days: 7
5151

.github/workflows/test-branch.yml

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ jobs:
1616
os: [ macos-latest, windows-latest, ubuntu-latest ]
1717
runs-on: ${{ matrix.os }}
1818
steps:
19-
2019
- uses: actions/checkout@v4
2120
- uses: actions/setup-java@v4
2221
with:
@@ -27,11 +26,46 @@ jobs:
2726
- name: Run All Tests
2827
uses: gradle/gradle-build-action@v3
2928
with:
30-
gradle-version: 8.3
29+
gradle-version: 8.5
3130
arguments: |
3231
assemble
3332
build
3433
allTests
3534
--info
3635
--warning-mode all
3736
37+
- name: Upload test reports
38+
uses: actions/upload-artifact@v4
39+
if: ${{ always() }}
40+
with:
41+
name: test-reports-${{ runner.os }}
42+
path: '**/build/reports'
43+
retention-days: 7
44+
45+
detekt-check:
46+
name: Detekt check
47+
runs-on: ubuntu-latest
48+
steps:
49+
- uses: actions/checkout@v4
50+
- uses: actions/setup-java@v4
51+
with:
52+
distribution: 'zulu'
53+
java-version: 11
54+
cache: 'gradle'
55+
- name: Run Detekt
56+
uses: gradle/gradle-build-action@v3
57+
with:
58+
gradle-version: 8.5
59+
arguments: |
60+
assemble
61+
detekt
62+
--info
63+
--warning-mode all
64+
65+
- name: Upload detekt reports
66+
uses: actions/upload-artifact@v4
67+
if: ${{ always() }}
68+
with:
69+
name: detekt-reports-${{ runner.os }}
70+
path: 'build/reports/detekt'
71+
retention-days: 7

.github/workflows/test-v4-branch.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ env:
88
IS_CI: true
99
GRADLE_OPTS: "-Dfile.encoding=UTF-8"
1010

11+
concurrency:
12+
group: '${{ github.workflow }}-${{ github.ref }}'
13+
cancel-in-progress: true
14+
1115
jobs:
1216
build-v4-test:
1317
name: Build and test
@@ -41,3 +45,39 @@ jobs:
4145
name: test-reports-${{ matrix.os }}
4246
path: '**/build/reports/tests'
4347
retention-days: 7
48+
49+
detekt-check:
50+
name: Detekt check
51+
runs-on: ubuntu-latest
52+
steps:
53+
- uses: actions/checkout@v4
54+
- uses: actions/setup-java@v4
55+
with:
56+
distribution: 'zulu'
57+
java-version: 11
58+
cache: 'gradle'
59+
- name: Run Detekt
60+
uses: gradle/gradle-build-action@v3
61+
with:
62+
gradle-version: 8.5
63+
arguments: |
64+
detekt
65+
--info
66+
--warning-mode all
67+
68+
- name: Upload detekt reports
69+
uses: actions/upload-artifact@v4
70+
if: ${{ always() }}
71+
with:
72+
name: detekt-reports
73+
path: 'build/reports/detekt'
74+
retention-days: 7
75+
76+
# https://detekt.dev/docs/introduction/reporting/#integration-with-github-code-scanning
77+
# Make sure we always run this upload task,
78+
# because the previous step may fail if there are findings.
79+
- name: Upload SARIF to GitHub using the upload-sarif action
80+
uses: github/codeql-action/upload-sarif@v2
81+
if: ${{ always() }}
82+
with:
83+
sarif_file: 'build/reports/detekt/detekt.sarif'

.idea/codeStyles/Project.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/codeStyleConfig.xml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/simbot__detekt_.xml

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle.kts

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,21 @@
2121
*
2222
*/
2323

24+
import io.gitlab.arturbosch.detekt.Detekt
2425
import love.forte.gradle.common.core.project.setup
2526

2627
plugins {
2728
idea
2829
id("simbot.dokka-multi-module")
2930
id("com.github.gmazzo.buildconfig") version "4.1.2" apply false
30-
id("io.gitlab.arturbosch.detekt")
31+
alias(libs.plugins.detekt)
3132
id("simbot.nexus-publish")
3233
id("simbot.changelog-generator")
3334

3435
// https://www.jetbrains.com/help/qodana/code-coverage.html
3536
// https://github.com/Kotlin/kotlinx-kover
3637
id("org.jetbrains.kotlinx.kover") version "0.7.6"
38+
3739
}
3840

3941
setup(P.Simbot)
@@ -74,12 +76,12 @@ subprojects {
7476

7577
fun Project.hasKtP(): Boolean {
7678
return plugins.findPlugin("org.jetbrains.kotlin.jvm") != null ||
77-
plugins.findPlugin("org.jetbrains.kotlin.multiplatform") != null
79+
plugins.findPlugin("org.jetbrains.kotlin.multiplatform") != null
7880
}
7981

8082
if (hasKtP()) {
8183
// apply(plugin = "io.gitlab.arturbosch.detekt")
82-
applyDetekt()
84+
// applyDetekt()
8385
if ("gradle" !in name) {
8486
useK2()
8587
logger.info("Enable K2 for {}", this)
@@ -91,23 +93,51 @@ subprojects {
9193

9294
}
9395

94-
fun Project.applyDetekt() {
95-
// apply(plugin = "io.gitlab.arturbosch.detekt")
96-
//
97-
// detekt {
98-
// // buildUponDefaultConfig = true
99-
// config.from(rootProject.projectDir.resolve(".detekt/config/detekt.yml"))
100-
// baseline = rootProject.projectDir.resolve(".detekt/baseline/detekt-baseline.xml")
101-
// // "detekt-baseline.xml"
102-
// dependencies {
103-
// detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.1")
104-
// }
105-
// }
96+
dependencies {
97+
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:${libs.versions.detekt.get()}")
98+
}
99+
100+
// config detekt
101+
detekt {
102+
source.setFrom(subprojects.map { it.projectDir.absoluteFile })
103+
config.setFrom(rootDir.resolve("config/detekt/detekt.yml"))
104+
baseline = rootDir.resolve("config/detekt/baseline.xml")
105+
// buildUponDefaultConfig = true
106+
parallel = true
107+
reportsDir = rootProject.layout.buildDirectory.dir("reports/detekt").get().asFile
108+
if (!isCi) {
109+
autoCorrect = true
110+
}
111+
basePath = projectDir.absolutePath
112+
}
113+
114+
// https://detekt.dev/blog/2019/03/03/configure-detekt-on-root-project/
115+
tasks.withType<Detekt>().configureEach {
116+
// internal 处理器不管
117+
exclude("internal-processors/**")
118+
119+
include("**/src/*Main/kotlin/**/*.kt")
120+
include("**/src/*Main/kotlin/**/*.java")
121+
include("**/src/*Main/java/**/*.kt")
122+
include("**/src/*Main/java/**/*.java")
123+
include("**/src/main/kotlin/**/*.kt")
124+
include("**/src/main/kotlin/**/*.java")
125+
include("**/src/main/java/**/*.kt")
126+
include("**/src/main/java/**/*.java")
127+
128+
exclude("**/src/*/resources/")
129+
exclude("**/build/")
130+
exclude("**/*Test/kotlin/")
131+
exclude("**/*Test/java/")
132+
exclude("**/test/kotlin/")
133+
exclude("**/test/java/")
106134
}
107135

108136
fun Project.applyKover(rp: Project) {
109-
val hasKt = (plugins.hasPlugin("org.jetbrains.kotlin.jvm")
110-
|| plugins.hasPlugin("org.jetbrains.kotlin.multiplatform"))
137+
val hasKt =
138+
plugins.hasPlugin("org.jetbrains.kotlin.jvm") ||
139+
plugins.hasPlugin("org.jetbrains.kotlin.multiplatform")
140+
111141

112142
if (hasKt) {
113143
apply(plugin = "org.jetbrains.kotlinx.kover")

buildSrc/build.gradle.kts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Project https://github.com/simple-robot/simpler-robot
55
66
*
7-
* This file is part of the Simple Robot Library.
7+
* This file is part of the Simple Robot Library (Alias: simple-robot, simbot, etc.).
88
*
99
* This program is free software: you can redistribute it and/or modify
1010
* it under the terms of the GNU Lesser General Public License as published by
@@ -47,10 +47,6 @@ dependencies {
4747

4848
// gradle common
4949
implementation(libs.bundles.gradle.common)
50-
51-
// detekt
52-
// 1.23.1
53-
implementation("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.23.5")
5450
}
5551

5652
idea {

buildSrc/src/main/kotlin/K2Config.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Project https://github.com/simple-robot/simpler-robot
55
66
*
7-
* This file is part of the Simple Robot Library.
7+
* This file is part of the Simple Robot Library (Alias: simple-robot, simbot, etc.).
88
*
99
* This program is free software: you can redistribute it and/or modify
1010
* it under the terms of the GNU Lesser General Public License as published by
@@ -26,6 +26,7 @@ import org.gradle.kotlin.dsl.withType
2626

2727

2828
fun Project.useK2(languageVersion: String = "2.0") {
29+
logger.warn("暂时关闭K2, 等待稳定版。The input languageVersion = {}", languageVersion)
2930
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
3031
kotlinOptions {
3132
// useK2

0 commit comments

Comments
 (0)