diff --git a/WORKSPACE b/WORKSPACE index 4475bc10..e6f76b82 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -27,7 +27,7 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") git_repository( name = "grab_bazel_common", - commit = "fe47feaee47d9f872514d29ca4ac4c462e1811eb", + commit = "3f9ff2c3351d76cf630e455430a6a7bc942e58f7", remote = "https://github.com/grab/grab-bazel-common.git", ) diff --git a/build.gradle b/build.gradle index 1710fa22..618cc447 100644 --- a/build.gradle +++ b/build.gradle @@ -98,7 +98,7 @@ grazel { rules { bazelCommon { gitRepository { - commit = "fe47feaee47d9f872514d29ca4ac4c462e1811eb" + commit = "3f9ff2c3351d76cf630e455430a6a7bc942e58f7" remote = "https://github.com/grab/grab-bazel-common.git" } toolchains { diff --git a/constants.gradle b/constants.gradle index 0e0c2692..5104caa3 100644 --- a/constants.gradle +++ b/constants.gradle @@ -15,7 +15,7 @@ */ ext { groupId = "com.grab.grazel" - versionName = "0.4.1-alpha.23" + versionName = "0.4.1-alpha.24" website = "https://grab.github.io/Grazel/" } diff --git a/flavor-libs/sample-library-flavor1/BUILD.bazel b/flavor-libs/sample-library-flavor1/BUILD.bazel index 335ec958..9c1c2900 100644 --- a/flavor-libs/sample-library-flavor1/BUILD.bazel +++ b/flavor-libs/sample-library-flavor1/BUILD.bazel @@ -5,6 +5,9 @@ kotlin_library( srcs = glob([ "src/main/java/com/grab/grazel/android/flavor/ModuleName.kt", ]), + lint_options = { + "enabled": "true", + }, visibility = [ "//visibility:public", ], diff --git a/flavor-libs/sample-library-flavor2/BUILD.bazel b/flavor-libs/sample-library-flavor2/BUILD.bazel index c11da62b..ca7425ea 100644 --- a/flavor-libs/sample-library-flavor2/BUILD.bazel +++ b/flavor-libs/sample-library-flavor2/BUILD.bazel @@ -5,6 +5,9 @@ kotlin_library( srcs = glob([ "src/main/java/com/grab/grazel/android/flavor/ModuleName.kt", ]), + lint_options = { + "enabled": "true", + }, visibility = [ "//visibility:public", ], diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/bazel/rules/KotlinRules.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/bazel/rules/KotlinRules.kt index 7744cff0..23be49f6 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/bazel/rules/KotlinRules.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/bazel/rules/KotlinRules.kt @@ -19,6 +19,7 @@ package com.grab.grazel.bazel.rules import com.grab.grazel.bazel.rules.Visibility.Public import com.grab.grazel.bazel.starlark.Assignee import com.grab.grazel.bazel.starlark.BazelDependency +import com.grab.grazel.bazel.starlark.LintConfigs import com.grab.grazel.bazel.starlark.StatementsBuilder import com.grab.grazel.bazel.starlark.add import com.grab.grazel.bazel.starlark.array @@ -26,6 +27,7 @@ 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.toObject import com.grab.grazel.extension.JavaCOptions import com.grab.grazel.extension.KotlinCOptions import com.grab.grazel.extension.KotlinToolChain @@ -146,7 +148,8 @@ fun StatementsBuilder.ktLibrary( plugins: List = emptyList(), assetsGlob: List = emptyList(), assetsDir: String? = null, - tags: List = emptyList() + tags: List = emptyList(), + lintConfigs: LintConfigs? = null, ) { load("@$GRAB_BAZEL_COMMON//rules:defs.bzl", "kotlin_library") @@ -184,6 +187,10 @@ fun StatementsBuilder.ktLibrary( tags.notEmpty { "tags" `=` array(tags.map(String::quote)) } + + if (lintConfigs?.merged?.isNotEmpty() == true) { + "lint_options" `=` lintConfigs.merged.toObject(quoteKeys = true, quoteValues = true) + } } } diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/Project.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/Project.kt index 91994167..ddfa0c8e 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/Project.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/Project.kt @@ -32,6 +32,7 @@ const val KOTLIN_PARCELIZE = "kotlin-parcelize" const val KOTLIN_KAPT = "kotlin-kapt" const val ANDROID_APPLICATION_PLUGIN = "com.android.application" const val ANDROID_LIBRARY_PLUGIN = "com.android.library" +const val LINT_PLUGIN_ID = "com.android.lint" const val ANDROID_DYNAMIC_FEATURE = "com.android.dynamic-feature" const val FIREBASE_CRASHLYTICS_PLUGIN = "com.google.firebase.crashlytics" const val GOOGLE_PLAY_SERVICES_PLUGIN = "com.google.firebase.crashlytics" diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidExtractor.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidExtractor.kt index e3f36088..8805f0f5 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidExtractor.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidExtractor.kt @@ -163,24 +163,22 @@ constructor( } } -private fun lintConfigs( +fun lintConfigs( lintOptions: LintOptions, project: Project ): LintConfigs { // enable lint for all targets by default val enabled = true - val configPath = if (lintOptions.lintConfig?.absolutePath != null) { - project.relativePath(lintOptions.lintConfig!!.absolutePath) - } else { - null - } - val baseLinePath = if (lintOptions.baselineFile?.absolutePath != null) { - project.relativePath(lintOptions.baselineFile!!.absolutePath) - } else { - null - } - return LintConfigs(enabled, configPath, baseLinePath) + return LintConfigs( + enabled, + lintOptions.lintConfig?.let { + project.relativePath(it) + }, + lintOptions.baselineFile?.let { + project.relativePath(it) + } + ) } internal interface AndroidBinaryDataExtractor : AndroidExtractor diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/kotlin/KotlinLibraryTarget.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/kotlin/KotlinLibraryTarget.kt index c367d3fe..d79ec63c 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/kotlin/KotlinLibraryTarget.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/kotlin/KotlinLibraryTarget.kt @@ -19,6 +19,7 @@ package com.grab.grazel.migrate.kotlin import com.grab.grazel.bazel.rules.Visibility import com.grab.grazel.bazel.rules.ktLibrary import com.grab.grazel.bazel.starlark.BazelDependency +import com.grab.grazel.bazel.starlark.LintConfigs import com.grab.grazel.bazel.starlark.StatementsBuilder import com.grab.grazel.migrate.BazelBuildTarget import com.grab.grazel.migrate.android.ResValuesData @@ -39,6 +40,7 @@ internal data class KotlinLibraryTarget( val plugins: List = emptyList(), val assetsGlob: List = emptyList(), val assetsDir: String? = null, + val lintConfigs: LintConfigs? = null ) : BazelBuildTarget { override fun statements(builder: StatementsBuilder) = builder { @@ -54,7 +56,8 @@ internal data class KotlinLibraryTarget( plugins = plugins, assetsGlob = assetsGlob, assetsDir = assetsDir, - tags = tags + tags = tags, + lintConfigs = lintConfigs ) } } \ No newline at end of file diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/kotlin/KotlinProjectData.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/kotlin/KotlinProjectData.kt index c5fa3105..0f49f90e 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/kotlin/KotlinProjectData.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/kotlin/KotlinProjectData.kt @@ -17,11 +17,13 @@ package com.grab.grazel.migrate.kotlin import com.grab.grazel.bazel.starlark.BazelDependency +import com.grab.grazel.bazel.starlark.LintConfigs data class KotlinProjectData( val name: String, val srcs: List, val res: List, val deps: List, - val tags: List + val tags: List, + val lintConfigs: LintConfigs ) \ No newline at end of file diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/kotlin/KotlinProjectDataExtractor.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/kotlin/KotlinProjectDataExtractor.kt index d2b75362..8c4e6299 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/kotlin/KotlinProjectDataExtractor.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/kotlin/KotlinProjectDataExtractor.kt @@ -16,11 +16,14 @@ package com.grab.grazel.migrate.kotlin +import com.android.builder.model.LintOptions import com.grab.grazel.GrazelExtension import com.grab.grazel.bazel.rules.KOTLIN_PARCELIZE_TARGET import com.grab.grazel.bazel.starlark.BazelDependency +import com.grab.grazel.bazel.starlark.LintConfigs import com.grab.grazel.extension.KotlinExtension import com.grab.grazel.gradle.ConfigurationScope +import com.grab.grazel.gradle.LINT_PLUGIN_ID import com.grab.grazel.gradle.dependencies.BuildGraphType import com.grab.grazel.gradle.dependencies.DependenciesDataSource import com.grab.grazel.gradle.dependencies.DependencyGraphs @@ -86,10 +89,32 @@ constructor( srcs = srcs, res = resources, deps = deps, - tags = tags + tags = tags, + lintConfigs = lintConfigs(project), ) } + fun lintConfigs(project: Project): LintConfigs { + return if (project.plugins.hasPlugin(LINT_PLUGIN_ID)) { + val lint = project.the() + LintConfigs( + enabled = true, + configPath = lint.lintConfig?.let { + project.relativePath(it) + }, + baselinePath = lint.baselineFile?.let { + project.relativePath(it) + }, + ) + } else { + LintConfigs( + enabled = true, // enable Lint by default even when its not enabled in gradle + configPath = null, + baselinePath = null, + ) + } + } + private fun Project.kotlinSources( sourceSets: NamedDomainObjectContainer, sourceSetType: SourceSetType diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/target/KotlinLibraryTargetBuilder.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/target/KotlinLibraryTargetBuilder.kt index 1f0a508f..6b7e5d66 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/target/KotlinLibraryTargetBuilder.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/target/KotlinLibraryTargetBuilder.kt @@ -75,6 +75,7 @@ constructor( res = res, deps = deps, tags = tags, + lintConfigs = lintConfigs ) } diff --git a/sample-kotlin-library/BUILD.bazel b/sample-kotlin-library/BUILD.bazel index b61520ce..19a4c84b 100644 --- a/sample-kotlin-library/BUILD.bazel +++ b/sample-kotlin-library/BUILD.bazel @@ -5,6 +5,10 @@ kotlin_library( srcs = glob([ "src/main/java/com/grab/grazel/sample/HelloWorld.kt", ]), + lint_options = { + "enabled": "true", + "baseline": "lint-baseline-kotlin.xml", + }, visibility = [ "//visibility:public", ], diff --git a/sample-kotlin-library/build.gradle b/sample-kotlin-library/build.gradle index a3440d82..12391616 100644 --- a/sample-kotlin-library/build.gradle +++ b/sample-kotlin-library/build.gradle @@ -16,6 +16,11 @@ apply plugin: "java-library" apply plugin: "kotlin" +apply plugin: "com.android.lint" + +lint { + baseline file("lint-baseline-kotlin.xml") +} dependencies { implementation fileTree(dir: "libs", include: ["*.jar"])