2
0

build.gradle.kts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
  2. import org.jlleitschuh.gradle.ktlint.KtlintExtension
  3. import org.jlleitschuh.gradle.ktlint.reporter.ReporterType
  4. plugins {
  5. // alias(libs.plugins.devtools.ksp) apply false
  6. alias(libs.plugins.android.application) apply false
  7. alias(libs.plugins.android.library) apply false
  8. alias(libs.plugins.compose) apply false
  9. alias(libs.plugins.compose.compiler) apply false
  10. alias(libs.plugins.kotlin.jvm) apply false
  11. alias(libs.plugins.kotlin.multiplatform) apply false
  12. alias(libs.plugins.app.icon.generator) apply false
  13. alias(libs.plugins.qodana)
  14. // alias(libs.plugins.kover)
  15. alias(libs.plugins.changelog) apply false
  16. alias(libs.plugins.gradle.ktlint)
  17. alias(libs.plugins.manes.versions)
  18. alias(libs.plugins.kotlin.android) apply false
  19. // id("com.github.gmazzo.buildconfig") version "5.6.5"
  20. }
  21. // ============================================================================
  22. // Code quality + dependency reporting -> /reports
  23. // - ben-manes: stable-only dependency-update report (rejects alpha/rc/dev/tethys/snapshot)
  24. // - ktlint: auto-format after build + report; report-only (never breaks the build)
  25. // - After every build: auto-format code, ktlint report, and (gated) dependency report.
  26. // Dependency check is ON by default; disable with -PdepCheck=false
  27. // ============================================================================
  28. // A version is "non-stable" if it is a milestone/preview build (alpha, beta, rc,
  29. // eap, dev, snapshot, tethys, …) — we never auto-suggest those over a stable current.
  30. fun isNonStable(version: String): Boolean {
  31. val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) }
  32. val regex = "^[0-9,.v-]+(-r)?$".toRegex()
  33. return !(stableKeyword || regex.matches(version))
  34. }
  35. val depCheckEnabled: Boolean = (findProperty("depCheck") as String?)?.toBooleanStrictOrNull() ?: true
  36. val reportsDir: Directory = rootProject.layout.projectDirectory.dir("reports")
  37. allprojects {
  38. apply(plugin = "com.github.ben-manes.versions")
  39. apply(plugin = "org.jlleitschuh.gradle.ktlint")
  40. extensions.configure<KtlintExtension> {
  41. ignoreFailures.set(true) // report only — never fail the build
  42. android.set(true)
  43. filter {
  44. // never lint/format generated or build output (compose resources, KSP, etc.)
  45. exclude { it.file.path.contains("${File.separator}build${File.separator}") }
  46. exclude { it.file.path.contains("generated") }
  47. }
  48. reporters {
  49. reporter(ReporterType.PLAIN)
  50. reporter(ReporterType.HTML)
  51. reporter(ReporterType.CHECKSTYLE)
  52. }
  53. }
  54. tasks.withType<DependencyUpdatesTask>().configureEach {
  55. rejectVersionIf { isNonStable(candidate.version) && !isNonStable(currentVersion) }
  56. outputDir = reportsDir.dir("dependencies").asFile.absolutePath
  57. reportfileName = "dependency-updates"
  58. outputFormatter = "plain,html"
  59. }
  60. }
  61. // Collect ktlint reports from every module into /reports/ktlint/<module>
  62. val collectKtlintReports by tasks.registering(Copy::class) {
  63. group = "reporting"
  64. description = "Collects ktlint reports from all modules into /reports/ktlint"
  65. allprojects.forEach { p ->
  66. from(p.layout.buildDirectory.dir("reports/ktlint")) { into(p.name) }
  67. }
  68. into(reportsDir.dir("ktlint"))
  69. duplicatesStrategy = DuplicatesStrategy.INCLUDE
  70. // ensure reports are produced before we collect them
  71. mustRunAfter(allprojects.flatMap { p -> p.tasks.matching { it.name == "ktlintCheck" || it.name == "ktlintFormat" } })
  72. }
  73. // Runs after every build: auto-format, ktlint report, and (gated) dependency-update report -> /reports
  74. val postBuildCodeCheck by tasks.registering {
  75. group = "verification"
  76. description = "Auto-formats code, runs ktlint and (gated) dependency-update report into /reports"
  77. dependsOn(":composeApp:ktlintFormat")
  78. if (depCheckEnabled) dependsOn(":composeApp:dependencyUpdates")
  79. finalizedBy(collectKtlintReports)
  80. }
  81. allprojects {
  82. tasks.matching { it.name == "build" }.configureEach {
  83. finalizedBy(rootProject.tasks.named("postBuildCodeCheck"))
  84. }
  85. }
  86. //buildConfig {
  87. // generateAtSync = true
  88. // sourceSets {
  89. // main {
  90. // packageName = "org.mjdev.desktop"
  91. // useKotlin = true
  92. // useJava = true
  93. // useGroovy = true
  94. // useScala = true
  95. // useXml = true
  96. // useProperties = true
  97. // }
  98. // }
  99. // buildConfigField("APP_NAME", project.name)
  100. // buildConfigField("APP_VERSION", provider { "\"${project.version}\"" })
  101. // buildConfigField("APP_SECRET", "Z3JhZGxlLWphdmEtYnVpbGRjb25maWctcGx1Z2lu")
  102. // buildConfigField<String>("OPTIONAL", null)
  103. // buildConfigField("BUILD_TIME", System.currentTimeMillis())
  104. // buildConfigField("FEATURE_ENABLED", true)
  105. // buildConfigField("MAGIC_NUMBERS", intArrayOf(1, 2, 3, 4))
  106. // buildConfigField("STRING_LIST", arrayOf("a", "b", "c"))
  107. // buildConfigField("MAP", mapOf("a" to 1, "b" to 2))
  108. // buildConfigField("FILE", File("aFile"))
  109. // buildConfigField("URI", uri("https://example.io"))
  110. // buildConfigField("com.github.gmazzo.buildconfig.demos.kts.SomeData", "DATA", "SomeData(\"a\", 1)")
  111. //}
  112. //dependencies {
  113. // kover(project(":composeApp"))
  114. //}
  115. //kover { reports { total { xml { onCheck = true } } } }