Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integrate bazel_rules_detekt #138

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
*.iml
.gradle
.fleet
.idea/caches
.idea
.idea/libraries
.idea/encodings.xml
.idea/gradle.xml
Expand Down
2 changes: 2 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ parcelize_rules()
configure_common_toolchains()

exports_files(["lint.xml"])

exports_files(["detekt-config.yml"])
46 changes: 45 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
name = "grab_bazel_common",
commit = "b3ced63a493c8990e1ab410e645111aa25fb7df7",
commit = "43dd907b72d07da8fc148eb0f4094da1419c52e7",
remote = "https://github.com/grab/grab-bazel-common.git",
)

Expand All @@ -46,6 +46,10 @@ load("@grab_bazel_common//rules:maven.bzl", "pin_bazel_common_dependencies")

pin_bazel_common_dependencies()

load("@rules_detekt//detekt:toolchains.bzl", "rules_detekt_toolchains")

rules_detekt_toolchains()

DAGGER_TAG = "2.47"

DAGGER_SHA = "154cdfa4f6f552a9873e2b4448f7a80415cb3427c4c771a50c6a8a8b434ffd0a"
Expand Down Expand Up @@ -237,6 +241,46 @@ load("@debug_maven//:defs.bzl", debug_maven_pinned_maven_install = "pinned_maven

debug_maven_pinned_maven_install()

maven_install(
name = "detekt_maven",
artifacts = [
"org.jetbrains.kotlin:kotlin-stdlib-common:1.7.21",
"org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.21",
"org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.21",
"org.jetbrains.kotlin:kotlin-stdlib:1.7.21",
"org.jetbrains:annotations:13.0",
"ru.kode:detekt-rules-compose:1.3.0",
],
excluded_artifacts = ["androidx.test.espresso:espresso-contrib"],
fail_if_repin_required = False,
fail_on_missing_checksum = False,
jetify = True,
jetify_include_list = [
"com.android.support:cardview-v7",
"com.android.support:support-annotations",
"com.android.support:support-compat",
"com.android.support:support-core-ui",
"com.android.support:support-core-utils",
],
maven_install_json = "//:detekt_maven_install.json",
override_targets = {
"org.jetbrains.kotlin:kotlin-stdlib": "@maven//:org_jetbrains_kotlin_kotlin_stdlib",
"org.jetbrains.kotlin:kotlin-stdlib-common": "@maven//:org_jetbrains_kotlin_kotlin_stdlib_common",
"org.jetbrains.kotlin:kotlin-stdlib-jdk7": "@maven//:org_jetbrains_kotlin_kotlin_stdlib_jdk7",
"org.jetbrains.kotlin:kotlin-stdlib-jdk8": "@maven//:org_jetbrains_kotlin_kotlin_stdlib_jdk8",
"org.jetbrains:annotations": "@maven//:org_jetbrains_annotations",
},
repositories = [
"https://repo.maven.apache.org/maven2/",
],
resolve_timeout = 1000,
version_conflict_policy = "pinned",
)

load("@detekt_maven//:defs.bzl", detekt_maven_pinned_maven_install = "pinned_maven_install")

detekt_maven_pinned_maven_install()

maven_install(
name = "lint_maven",
artifacts = [
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ plugins {
alias(libs.plugins.kotlin.parcelize) apply false
alias(libs.plugins.google.mobile.services) apply false
alias(libs.plugins.firebase.crashlytics) apply false
alias(libs.plugins.detekt) apply false
id "idea"
id "com.grab.grazel"
}
Expand Down Expand Up @@ -99,7 +100,7 @@ grazel {
rules {
bazelCommon {
gitRepository {
commit = "b3ced63a493c8990e1ab410e645111aa25fb7df7"
commit = "43dd907b72d07da8fc148eb0f4094da1419c52e7"
remote = "https://github.com/grab/grab-bazel-common.git"
}
toolchains {
Expand Down
2 changes: 1 addition & 1 deletion constants.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
ext {
groupId = "com.grab.grazel"
versionName = project.hasProperty("versionName") ? versionName : "0.4.1-alpha.30"
versionName = project.hasProperty("versionName") ? versionName : "0.4.1-alpha.31"

website = "https://grab.github.io/Grazel/"
}
Empty file added detekt-config.yml
Empty file.
127 changes: 127 additions & 0 deletions detekt_maven_install.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{
"__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL",
"__INPUT_ARTIFACTS_HASH": 697014258,
"__RESOLVED_ARTIFACTS_HASH": -2047095539,
"artifacts": {
"org.jetbrains.kotlin:kotlin-stdlib": {
"shasums": {
"jar": "d46a9d773ffb9dee4ff1a748ac845dc8e50005c589302951760a2b5187bddd19"
},
"version": "1.7.21"
},
"org.jetbrains.kotlin:kotlin-stdlib-common": {
"shasums": {
"jar": "e62bfeca236103a1017224b8a22a841db5dc4db49d80a39bd44dbb224684a66a"
},
"version": "1.7.21"
},
"org.jetbrains.kotlin:kotlin-stdlib-jdk7": {
"shasums": {
"jar": "b8caa0f9715a2187f4fa99906dae57cba10ceef9a7f808dbee8eaf36359558a5"
},
"version": "1.7.21"
},
"org.jetbrains.kotlin:kotlin-stdlib-jdk8": {
"shasums": {
"jar": "b32e4ae7ebb0572733fe439385bf034f5faee8b6c585d416fecf933e9491d38e"
},
"version": "1.7.21"
},
"org.jetbrains:annotations": {
"shasums": {
"jar": "ace2a10dc8e2d5fd34925ecac03e4988b2c0f851650c94b8cef49ba1bd111478"
},
"version": "13.0"
},
"ru.kode:detekt-rules-compose": {
"shasums": {
"jar": "99ad0c09ca0a87d2ed7a0441b7adc3bd25aa51ffa2ff6eaa075165356f09d412"
},
"version": "1.3.0"
}
},
"dependencies": {
"org.jetbrains.kotlin:kotlin-stdlib": [
"org.jetbrains.kotlin:kotlin-stdlib-common",
"org.jetbrains:annotations"
],
"org.jetbrains.kotlin:kotlin-stdlib-jdk7": [
"org.jetbrains.kotlin:kotlin-stdlib"
],
"org.jetbrains.kotlin:kotlin-stdlib-jdk8": [
"org.jetbrains.kotlin:kotlin-stdlib",
"org.jetbrains.kotlin:kotlin-stdlib-jdk7"
],
"ru.kode:detekt-rules-compose": [
"org.jetbrains.kotlin:kotlin-stdlib-jdk8"
]
},
"packages": {
"org.jetbrains.kotlin:kotlin-stdlib": [
"kotlin",
"kotlin.annotation",
"kotlin.collections",
"kotlin.collections.builders",
"kotlin.collections.unsigned",
"kotlin.comparisons",
"kotlin.concurrent",
"kotlin.contracts",
"kotlin.coroutines",
"kotlin.coroutines.cancellation",
"kotlin.coroutines.intrinsics",
"kotlin.coroutines.jvm.internal",
"kotlin.experimental",
"kotlin.internal",
"kotlin.io",
"kotlin.js",
"kotlin.jvm",
"kotlin.jvm.functions",
"kotlin.jvm.internal",
"kotlin.jvm.internal.markers",
"kotlin.jvm.internal.unsafe",
"kotlin.math",
"kotlin.properties",
"kotlin.random",
"kotlin.ranges",
"kotlin.reflect",
"kotlin.sequences",
"kotlin.system",
"kotlin.text",
"kotlin.time"
],
"org.jetbrains.kotlin:kotlin-stdlib-jdk7": [
"kotlin.internal.jdk7",
"kotlin.io.path",
"kotlin.jdk7"
],
"org.jetbrains.kotlin:kotlin-stdlib-jdk8": [
"kotlin.collections.jdk8",
"kotlin.internal.jdk8",
"kotlin.jvm.jdk8",
"kotlin.jvm.optionals",
"kotlin.random.jdk8",
"kotlin.streams.jdk8",
"kotlin.text.jdk8",
"kotlin.time.jdk8"
],
"org.jetbrains:annotations": [
"org.intellij.lang.annotations",
"org.jetbrains.annotations"
],
"ru.kode:detekt-rules-compose": [
"ru.kode.detekt.rule.compose",
"ru.kode.detekt.rule.compose.node"
]
},
"repositories": {
"https://repo.maven.apache.org/maven2/": [
"org.jetbrains.kotlin:kotlin-stdlib",
"org.jetbrains.kotlin:kotlin-stdlib-common",
"org.jetbrains.kotlin:kotlin-stdlib-jdk7",
"org.jetbrains.kotlin:kotlin-stdlib-jdk8",
"org.jetbrains:annotations",
"ru.kode:detekt-rules-compose"
]
},
"version": "2"
}
2 changes: 1 addition & 1 deletion flavors/sample-library-demo/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ kotlin_library(
"src/main/java/com/grab/grazel/android/flavor/ModuleName.kt",
]),
lint_options = {
"enabled": True,
"enabled": False,
},
visibility = [
"//visibility:public",
Expand Down
2 changes: 1 addition & 1 deletion flavors/sample-library-full/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ kotlin_library(
"src/main/java/com/grab/grazel/android/flavor/ModuleName.kt",
]),
lint_options = {
"enabled": True,
"enabled": False,
},
visibility = [
"//visibility:public",
Expand Down
8 changes: 7 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ activity-compose = "1.7.2"
annotation-jvm = "1.6.0"
crashlytics = "2.9.9"
dagger = "2.47"
detekt-gradle-plugin = "1.23.6"
detekt-rules-compose-version = "1.3.0"
dokka = "1.4.32"
emoji2 = "1.3.0"
google-services = "4.3.15"
Expand All @@ -39,6 +41,7 @@ slack-lint-checks = "0.2.3"
timber = "5.0.1"
auto-service = "1.1.1"
truth = "1.1.3"
detekt = "1.23.6"

[libraries]
android-gradle-plugin = { module = "com.android.tools.build:gradle", version.ref = "android-gradle-plugin" }
Expand Down Expand Up @@ -72,13 +75,15 @@ androidx-compose-animation-core = { module = "androidx.compose.animation:animati
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "activity-compose" }
databinding-common = { module = "androidx.databinding:databinding-common", version.ref = "android-gradle-plugin" }
databinding-runtime = { module = "androidx.databinding:databinding-runtime", version.ref = "android-gradle-plugin" }
detekt-gradle-plugin = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detekt-gradle-plugin" }
dokka-gradle-plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" }
google-dagger = { module = "com.google.dagger:dagger", version.ref = "dagger" }
google-dagger-compiler = { module = "com.google.dagger:dagger-compiler", version.ref = "dagger" }
google-guava = { module = "com.google.guava:guava", version.ref = "guava" }
google-truth = { module = "com.google.truth:truth", version.ref = "truth" }
javapoet = { module = "com.squareup:javapoet", version.ref = "javapoet" }
junit = { module = "junit:junit", version.ref = "junit" }
kode-detekt-rules-compose = { module = "ru.kode:detekt-rules-compose", version.ref = "detekt-rules-compose-version" }
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
kotlin-serialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlin-serialization" }
Expand Down Expand Up @@ -107,4 +112,5 @@ kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" }
kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }
kotlin-dsl = { id = "org.gradle.kotlin.kotlin-dsl", version.ref = "kotlin-dsl" }
gradle-publish = { id = "com.gradle.plugin-publish", version.ref = "gradle-plugin-publish" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
2 changes: 1 addition & 1 deletion grazel-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ dependencies {
implementation platform("org.jetbrains.kotlin:kotlin-bom")
implementation libs.kotlin.gradle.plugin
compileOnly libs.android.gradle.plugin

compileOnly libs.detekt.gradle.plugin
implementation libs.google.guava
implementation libs.picnic

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import com.grab.grazel.bazel.starlark.asString
import com.grab.grazel.bazel.starlark.glob
import com.grab.grazel.bazel.starlark.load
import com.grab.grazel.bazel.starlark.quote
import com.grab.grazel.bazel.starlark.toDetektOptionsStatement
import com.grab.grazel.bazel.starlark.toObject
import com.grab.grazel.migrate.android.BuildConfigData
import com.grab.grazel.migrate.android.DetektConfigData
import com.grab.grazel.migrate.android.LintConfigData
import com.grab.grazel.migrate.android.ResValuesData

Expand Down Expand Up @@ -140,6 +142,7 @@ internal fun StatementsBuilder.androidBinary(
assetsDir: String? = null,
buildConfigData: BuildConfigData,
lintConfigData: LintConfigData? = null,
detektConfigData: DetektConfigData? = null,
resConfigFilters: Set<String> = emptySet(),
) {
load("@$GRAB_BAZEL_COMMON//rules:defs.bzl", "android_binary")
Expand Down Expand Up @@ -186,10 +189,13 @@ internal fun StatementsBuilder.androidBinary(
if (!resValuesData.isEmpty) {
"res_values" `=` resValuesData.merged.toObject(quoteKeys = true, quoteValues = true)
}

if (lintConfigData?.merged?.isNotEmpty() == true) {
"lint_options" `=` lintConfigData.merged.toObject()
}
if (detektConfigData?.merged?.isNotEmpty() == true) {
load("@$GRAB_BAZEL_COMMON//rules:defs.bzl", "detekt_options")
"detekt_options" `=` detektConfigData.merged.toDetektOptionsStatement()
}
}
}

Expand All @@ -209,7 +215,8 @@ internal fun StatementsBuilder.androidLibrary(
assetsDir: String? = null,
resValuesData: ResValuesData,
buildConfigData: BuildConfigData,
lintConfigData: LintConfigData?
lintConfigData: LintConfigData?,
detektConfigData: DetektConfigData?,
) {
load("@$GRAB_BAZEL_COMMON//rules:defs.bzl", "android_library")
rule("android_library") {
Expand Down Expand Up @@ -253,6 +260,10 @@ internal fun StatementsBuilder.androidLibrary(
if (lintConfigData?.merged?.isNotEmpty() == true) {
"lint_options" `=` lintConfigData.merged.toObject()
}
if (detektConfigData?.merged?.isNotEmpty() == true) {
load("@$GRAB_BAZEL_COMMON//rules:defs.bzl", "detekt_options")
"detekt_options" `=` detektConfigData.merged.toDetektOptionsStatement()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ fun StatementsBuilder.toolAndroidRepository(
add("google_services_workspace_dependencies()")
}

/**
* rules detekt is coming from bazel common
*/
fun StatementsBuilder.detektToolchain() {
load(
"@rules_detekt//detekt:toolchains.bzl",
"rules_detekt_toolchains"
)
add("rules_detekt_toolchains()")
}

/**
* Adds a Google services XML target required by crashlytics and other
* google services
Expand Down
Loading
Loading