Skip to content

Instantly share code, notes, and snippets.

@pranaypatel512
Created May 19, 2023 08:44
Show Gist options
  • Save pranaypatel512/509e8c80658559e8935a4e76db0ce4f4 to your computer and use it in GitHub Desktop.
Save pranaypatel512/509e8c80658559e8935a4e76db0ce4f4 to your computer and use it in GitHub Desktop.
Githook blog reference
import io.gitlab.arturbosch.detekt.Detekt
plugins {
// this is necessary to avoid the plugins to be loaded multiple times
// in each subproject's classloader
// ===== Other main pluging of project ====
id("org.jlleitschuh.gradle.ktlint").apply(false) // https://github.com/jlleitschuh/ktlint-gradle
id("io.gitlab.arturbosch.detekt").apply(false) // https://github.com/detekt/detekt
//if you using version catalog
alias(libs.plugins.ktLint)
alias(libs.plugins.detekt)
}
allprojects {
repositories {
google()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
apply(plugin = "org.jlleitschuh.gradle.ktlint")
ktlint {
debug.set(true)
verbose.set(true)
android.set(false)
outputToConsole.set(true)
outputColorName.set("RED")
filter {
enableExperimentalRules.set(true)
exclude { projectDir.toURI().relativize(it.file.toURI()).path.contains("/generated/") }
include("**/kotlin/**")
}
}
}
detekt {
buildUponDefaultConfig = true // preconfigure defaults
allRules = false // activate all available (even unstable) rules.
autoCorrect = true
parallel = true
config = files("config/detekt/detekt.yml")
}
tasks.withType<Detekt>().configureEach {
reports {
html.required.set(true) // observe findings in your browser with structure and code snippets
txt.required.set(true) // similar to the console output, contains issue signature to manually edit baseline files
md.required.set(true) // simple Markdown format
}
}
tasks.withType<Detekt>().configureEach {
jvmTarget = "17"
}
tasks.withType<io.gitlab.arturbosch.detekt.DetektCreateBaselineTask>().configureEach {
jvmTarget = "17"
}
subprojects {
apply(plugin = "io.gitlab.arturbosch.detekt")
detekt {
parallel = true
config = files("${project.rootDir}/config/detekt/detekt.yml")
}
}
tasks.register("clean").configure {
delete("build")
}
tasks.register("copyGitHooks", Copy::class.java) {
description = "Copies the git hooks from /git-hooks to the .git folder."
group = "git hooks"
from("$rootDir/scripts/pre-commit")
into("$rootDir/.git/hooks/")
}
tasks.register("installGitHooks", Exec::class.java) {
description = "Installs the pre-commit git hooks from /git-hooks."
group = "git hooks"
workingDir = rootDir
commandLine = listOf("chmod")
args("-R", "+x", ".git/hooks/")
dependsOn("copyGitHooks")
doLast {
logger.info("Git hook installed successfully.")
}
}
afterEvaluate {
tasks.getByPath(":shared:preBuild").dependsOn(":installGitHooks")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment