Skip to content

Commit 7d7549a

Browse files
authored
Merge pull request #1737 from android/av/add-androidx-lint-gradle
Add androidx.lint:lint-gradle to build-logic
2 parents e861bcf + e4681fc commit 7d7549a

File tree

6 files changed

+21
-8
lines changed

6 files changed

+21
-8
lines changed

build-logic/convention/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
*/
1616

1717
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
18-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
1918

2019
plugins {
2120
`kotlin-dsl`
21+
alias(libs.plugins.android.lint)
2222
}
2323

2424
group = "com.google.samples.apps.nowinandroid.buildlogic"
@@ -46,6 +46,7 @@ dependencies {
4646
compileOnly(libs.ksp.gradlePlugin)
4747
compileOnly(libs.room.gradlePlugin)
4848
implementation(libs.truth)
49+
lintChecks(libs.androidx.lint.gradle)
4950
}
5051

5152
tasks {

build-logic/convention/src/main/kotlin/AndroidApplicationJacocoConventionPlugin.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
import com.android.build.api.dsl.ApplicationExtension
1718
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
18-
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
1919
import com.google.samples.apps.nowinandroid.configureJacoco
2020
import org.gradle.api.Plugin
2121
import org.gradle.api.Project
@@ -25,7 +25,7 @@ class AndroidApplicationJacocoConventionPlugin : Plugin<Project> {
2525
override fun apply(target: Project) {
2626
with(target) {
2727
pluginManager.apply("jacoco")
28-
val androidExtension = extensions.getByType<BaseAppModuleExtension>()
28+
val androidExtension = extensions.getByType<ApplicationExtension>()
2929

3030
androidExtension.buildTypes.configureEach {
3131
enableAndroidTestCoverage = true

build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/AndroidCompose.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ internal fun Project.configureAndroidCompose(
5353

5454
extensions.configure<ComposeCompilerGradlePluginExtension> {
5555
fun Provider<String>.onlyIfTrue() = flatMap { provider { it.takeIf(String::toBoolean) } }
56-
fun Provider<*>.relativeToRootProject(dir: String) = flatMap {
57-
rootProject.layout.buildDirectory.dir(projectDir.toRelativeString(rootDir))
56+
fun Provider<*>.relativeToRootProject(dir: String) = map {
57+
isolated.rootProject.projectDirectory
58+
.dir("build")
59+
.dir(projectDir.toRelativeString(rootDir))
5860
}.map { it.dir(dir) }
5961

6062
project.providers.gradleProperty("enableComposeCompilerMetrics").onlyIfTrue()
@@ -66,6 +68,6 @@ internal fun Project.configureAndroidCompose(
6668
.let(reportsDestination::set)
6769

6870
stabilityConfigurationFile =
69-
rootProject.layout.projectDirectory.file("compose_compiler_config.conf")
71+
isolated.rootProject.projectDirectory.file("compose_compiler_config.conf")
7072
}
7173
}

build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Badging.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@ fun Project.configureBadgingTasks(
140140

141141
val updateBadgingTaskName = "update${capitalizedVariantName}Badging"
142142
tasks.register<Copy>(updateBadgingTaskName) {
143-
from(generateBadging.get().badging)
143+
from(generateBadging.map(GenerateBadgingTask::badging))
144144
into(project.layout.projectDirectory)
145145
}
146146

147147
val checkBadgingTaskName = "check${capitalizedVariantName}Badging"
148148
tasks.register<CheckBadgingTask>(checkBadgingTaskName) {
149149
goldenBadging = project.layout.projectDirectory.file("${variant.name}-badging.txt")
150150

151-
generatedBadging = generateBadging.get().badging
151+
generatedBadging.set(generateBadging.flatMap(GenerateBadgingTask::badging))
152152

153153
this.updateBadgingTaskName = updateBadgingTaskName
154154

build-logic/settings.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17+
pluginManagement {
18+
repositories {
19+
gradlePluginPortal()
20+
google()
21+
}
22+
}
23+
1724
dependencyResolutionManagement {
1825
repositories {
1926
google {

gradle/libs.versions.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ androidxDataStore = "1.1.1"
1515
androidxEspresso = "3.6.1"
1616
androidxHiltNavigationCompose = "1.2.0"
1717
androidxLifecycle = "2.8.7"
18+
androidxLintGradle = "1.0.0-alpha03"
1819
androidxMacroBenchmark = "1.3.3"
1920
androidxMetrics = "1.0.0-beta01"
2021
androidxNavigation = "2.8.5"
@@ -92,6 +93,7 @@ androidx-hilt-navigation-compose = { group = "androidx.hilt", name = "hilt-navig
9293
androidx-lifecycle-runtimeCompose = { group = "androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "androidxLifecycle" }
9394
androidx-lifecycle-runtimeTesting = { group = "androidx.lifecycle", name = "lifecycle-runtime-testing", version.ref = "androidxLifecycle" }
9495
androidx-lifecycle-viewModelCompose = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "androidxLifecycle" }
96+
androidx-lint-gradle = { group = "androidx.lint", name = "lint-gradle", version.ref = "androidxLintGradle" }
9597
androidx-metrics = { group = "androidx.metrics", name = "metrics-performance", version.ref = "androidxMetrics" }
9698
androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "androidxNavigation" }
9799
androidx-navigation-testing = { group = "androidx.navigation", name = "navigation-testing", version.ref = "androidxNavigation" }
@@ -161,6 +163,7 @@ room-gradlePlugin = { group = "androidx.room", name = "room-gradle-plugin", vers
161163
[plugins]
162164
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }
163165
android-library = { id = "com.android.library", version.ref = "androidGradlePlugin" }
166+
android-lint = { id = "com.android.lint", version.ref = "androidGradlePlugin" }
164167
android-test = { id = "com.android.test", version.ref = "androidGradlePlugin" }
165168
baselineprofile = { id = "androidx.baselineprofile", version.ref = "androidxMacroBenchmark"}
166169
compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }

0 commit comments

Comments
 (0)