How to test a GradleScanner with project dependency references

1,070 views
Skip to first unread message

John Rodriguez

unread,
Nov 21, 2024, 9:24:20 PM11/21/24
to lint-dev
I've written a detector that errors when the legacy project dependency syntax is used in a Gradle build script, favoring the typesafe accessor syntax, i.e.,:

instead of
```
implementation project(":foo:bar")
```

use:
```
implementation projects.foo.bar
```

but I can't get the following test set up properly:

```
  @Test
  fun `legacy project path syntax detects error`() {
    lint()
      .files(
        gradle(
          """
          apply plugin: 'com.android.library'
          dependencies {
            implementation project(":foo:bar")
          }
          """
        ).indented()
      )
      .issues(GradleProjectPathDetector.LEGACY_PROJECT_PATH_SYNTAX)
      .run()
      .expect("") // left blank, so that a test failure will inform what to paste here
      .expectFixDiffs("") // ditto
  }
```

I tried adding a settings.gradle to declare 2 modules and an empty foo/bar/build.gradle to appease the test run, but that didn't work.

I also stepped through GradleModelMocker and its associated test, but looks like there's either no support for this at the moment, or I'm just missing something.
Reply all
Reply to author
Forward
0 new messages