-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from uzzu/4.x
4.x
- Loading branch information
Showing
20 changed files
with
1,020 additions
and
113 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -1,33 +1,100 @@ | ||
import io.gitlab.arturbosch.detekt.Detekt | ||
import io.gitlab.arturbosch.detekt.report.ReportMergeTask | ||
import kotlin.streams.asSequence | ||
import java.nio.file.FileSystems | ||
import java.nio.file.Files | ||
import java.nio.file.Path | ||
import java.nio.file.Paths | ||
|
||
plugins { | ||
base | ||
id("co.uzzu.dotenv.gradle") version "3.0.0" | ||
kotlin("jvm") version "1.4.31" apply false | ||
id("org.jlleitschuh.gradle.ktlint") version "11.0.0" | ||
alias(libs.plugins.dotenv.gradle) | ||
alias(libs.plugins.detekt) | ||
alias(libs.plugins.kotlin.jvm) apply false | ||
alias(libs.plugins.gradle.plugin.publish) apply false | ||
} | ||
|
||
val reportMerge by tasks.registering(ReportMergeTask::class) { | ||
output.set(rootProject.layout.buildDirectory.file("reports/detekt/detekt-merged-report.sarif")) | ||
} | ||
|
||
detektConfigurationRoot(reportMerge) | ||
|
||
subprojects { | ||
apply(plugin = "io.gitlab.arturbosch.detekt") | ||
detektConfigurationShared(reportMergeTask = reportMerge) | ||
} | ||
|
||
// region detekt configuration | ||
|
||
fun Project.detektConfigurationRoot( | ||
reportMergeTask: TaskProvider<ReportMergeTask>, | ||
) { | ||
val allKtsFiles = allKtsFiles() | ||
detektConfigurationShared( | ||
reportMergeTask = reportMergeTask, | ||
source = allKtsFiles | ||
+ allBuildSrcKtFiles() | ||
+ files("src"), | ||
) | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
mavenCentral() | ||
fun Project.detektConfigurationShared( | ||
reportMergeTask: TaskProvider<ReportMergeTask>, | ||
source: List<Any> = listOf(files("src")), | ||
detektConfig: File = rootProject.file("./gradle/detekt.yml"), | ||
) { | ||
detekt { | ||
buildUponDefaultConfig = true | ||
config.setFrom(detektConfig) | ||
this.source.setFrom(source) | ||
ignoreFailures = false | ||
debug = false | ||
parallel = true | ||
} | ||
|
||
tasks.withType<Detekt>().configureEach { | ||
finalizedBy(reportMerge) | ||
reports.sarif.required = true | ||
} | ||
|
||
reportMergeTask { | ||
input.from(tasks.withType<Detekt>().map { it.sarifReportFile }) | ||
} | ||
} | ||
|
||
ktlint { | ||
verbose.set(true) | ||
outputToConsole.set(true) | ||
reporters { | ||
reporter(org.jlleitschuh.gradle.ktlint.reporter.ReporterType.CHECKSTYLE) | ||
fun Project.allBuildSrcKtFiles(): List<Path> { | ||
if (!file(rootProject.projectDir.path + "/buildSrc").exists()) { | ||
return emptyList() | ||
} | ||
ignoreFailures.set(true) | ||
val ignoringPath = listOf(".git/", "build/", ".gradle/") | ||
val ktPattern = "glob:**/*.kt" | ||
val ktsPattern = "glob:**/*.kts" | ||
val ktMatcher = FileSystems.getDefault().getPathMatcher(ktPattern) | ||
val ktsMatcher = FileSystems.getDefault().getPathMatcher(ktsPattern) | ||
val results = Files.walk(Paths.get(rootProject.projectDir.path + "/buildSrc")) | ||
.asSequence() | ||
.filter { | ||
val path = it.toString() | ||
!ignoringPath.contains(path) && | ||
(ktMatcher.matches(it) || ktsMatcher.matches(it)) | ||
} | ||
.toList() | ||
return results | ||
} | ||
|
||
subprojects { | ||
apply(plugin = "org.jlleitschuh.gradle.ktlint") | ||
ktlint { | ||
verbose.set(true) | ||
outputToConsole.set(true) | ||
reporters { | ||
reporter(org.jlleitschuh.gradle.ktlint.reporter.ReporterType.CHECKSTYLE) | ||
fun Project.allKtsFiles(): List<Path> { | ||
val ignoringPath = listOf(".git/", "build/", ".gradle/", "src/") | ||
val pattern = "glob:**/*.kts" | ||
val matcher = FileSystems.getDefault().getPathMatcher(pattern) | ||
val results = Files.walk(Paths.get(projectDir.path)) | ||
.asSequence() | ||
.filter { | ||
val path = it.toString() | ||
!ignoringPath.contains(path) && matcher.matches(it) | ||
} | ||
ignoreFailures.set(true) | ||
} | ||
.toList() | ||
return results | ||
} | ||
|
||
// endregion |
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
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
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
plugins { | ||
base | ||
id("co.uzzu.dotenv.gradle") version "3.0.0" | ||
id("co.uzzu.dotenv.gradle") version "4.0.0" | ||
} | ||
|
||
println(env.FOO.value) |
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
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
Oops, something went wrong.