Hey there :wave: I work on an Android project tha...
# android
s
Hey there 👋 I work on an Android project that contains custom lint rules. The lint module contains the below dependencies block:
Copy code
dependencies {
    compileOnly("com.android.tools.lint:lint-api:lint-version")
    compileOnly("com.android.tools.lint:lint-checks:lint-version")
    testImplementation("com.android.tools.lint:lint-tests:lint-version")
    testImplementation(libs.kotlin.test.junit)
}
It uses Gradle version catalogs, but it is probably obvious which dependencies it is referring to. I am in the process of migrating from Kotlin 1.8.21 to 1.9.10 and all of a sudden the custom lint tests started failing with errors like this:
Copy code
Cannot access class 'com.android.tools.lint.detector.api.Issue'. Check your module classpath for missing or conflicting dependencies
Basically, unit tests cannot resolve dependencies that are configured with
compileOnly
. That used to work before migrating to Kotlin 1.9+. I found a way to fix the problem by adding the below configuration block:
Copy code
configurations {
    // Give tests visibility into dependencies configured as compileOnly
    testImplementation.extendsFrom(compileOnly)
}
Does anyone know why Kotlin 1.9+ would cause this issue? Is my configurations block the correct way to solve it? Thanks!
a
I’m pretty sure you should be using the lintChecks configuration instead
👀 2
Our project does that
Not sure if you need compile only
s
The
lint
module is depended on using
lingChecks
a
Ah my bad
We’re on kotlin 1.9 , agp 8.0, gradle 8.0, and have a custom lint project too that depend similarly as you
s
Ah cool, even the NowInAndroid app has a similar setup, but it does not have unit tests for the custom lint rules.
The lint rules work fine for us with Kotlin 1.9, Gradle and AGP 8+. The problem is just the unit tests for the custom lint rules.
a
Oh the wording made it sounded like unit tests in general were failing. You mean the unit tests for the lint checks themselves
s
Exactly, sorry for the confusion
c
maybe check out my project, it has tests for the lints. https://github.com/chrimaeon/lint-logdebug
c
Are you using k2 compiler?
s
I will check those out @Chrimaeon, thanks! @Colton Idle nope, not using K2 yet.
Thanks for sharing those repos @Chrimaeon! I was missing the
testImplementation("com.android.tools.lint:lint:lint-version")
dependency. I wonder why that only became a problem when I migrated to Kotlin 1.9+ and not before 🤔