代码拉取完成,页面将自动刷新
import com.android.build.gradle.BaseExtension
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType
plugins {
id(GradlePluginId.DETEKT)
id(GradlePluginId.KTLINT_GRADLE)
id(GradlePluginId.GRADLE_VERSION_PLUGIN)
id(GradlePluginId.KOTLIN_JVM) apply false
id(GradlePluginId.KOTLIN_ANDROID) apply false
id(GradlePluginId.KOTLIN_ANDROID_EXTENSIONS) apply false
id(GradlePluginId.ANDROID_APPLICATION) apply false
id(GradlePluginId.ANDROID_DYNAMIC_FEATURE) apply false
id(GradlePluginId.ANDROID_LIBRARY) apply false
id(GradlePluginId.SAFE_ARGS) apply false
}
// all projects = root project + sub projects
allprojects {
repositories {
google()
jcenter()
}
// We want to apply ktlint at all project level because it also checks build gradle files
apply(plugin = GradlePluginId.KTLINT_GRADLE)
// Ktlint configuration for sub-projects
ktlint {
version.set(CoreVersion.KTLINT)
verbose.set(true)
android.set(true)
// Uncomment below line and run .\gradlew ktlintCheck to see check ktlint experimental rules
// enableExperimentalRules.set(true)
reporters {
reporter(ReporterType.CHECKSTYLE)
}
filter {
exclude { element -> element.file.path.contains("generated/") }
}
}
}
subprojects {
tasks.withType<Test> {
maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).takeIf { it > 0 } ?: 1
}
apply(plugin = GradlePluginId.DETEKT)
detekt {
config = files("${project.rootDir}/detekt.yml")
parallel = true
}
afterEvaluate {
configureAndroid()
}
}
fun Project.configureAndroid() {
(project.extensions.findByName("android") as? BaseExtension)?.run {
sourceSets {
map { it.java.srcDir("src/${it.name}/kotlin") }
}
}
}
// JVM target applied to all Kotlin tasks across all sub-projects
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString()
}
tasks {
// Gradle versions plugin configuration
"dependencyUpdates"(DependencyUpdatesTask::class) {
resolutionStrategy {
componentSelection {
all {
// Do not show pre-release version of library in generated dependency report
val rejected = listOf("alpha", "beta", "rc", "cr", "m", "preview")
.map { qualifier -> Regex("(?i).*[.-]$qualifier[.\\d-]*") }
.any { it.matches(candidate.version) }
if (rejected) {
reject("Release candidate")
}
// kAndroid newest version is 0.8.8 (jcenter), however maven repository contains version 0.8.7 and
// plugin fails to recognize it correctly
if (candidate.group == "com.pawegio.kandroid") {
reject("version ${candidate.version} is broken for ${candidate.group}'")
}
}
}
}
}
}
task("staticCheck") {
description =
"""Mimics all static checks that run on CI.
Note that this task is intended to run locally (not on CI), because on CI we prefer to have parallel execution
and separate reports for each check (multiple statuses eg. on github PR page).
""".trimMargin()
group = "verification"
afterEvaluate {
// Filter modules with "lintDebug" task (non-Android modules do not have lintDebug task)
val lintTasks = subprojects.mapNotNull { "${it.name}:lintDebug" }
// Get modules with "testDebugUnitTest" task (app module does not have it)
val testTasks = subprojects.mapNotNull { "${it.name}:testDebugUnitTest" }
.filter { it != "app:testDebugUnitTest" }
// All task dependencies
val taskDependencies =
mutableListOf("app:assembleAndroidTest", "ktlintCheck", "detekt").also {
it.addAll(lintTasks)
it.addAll(testTasks)
}
// By defining Gradle dependency all dependent tasks will run before this "empty" task
dependsOn(taskDependencies)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。