5

I'm attempting to create a baseline lint file for my Android project. I've got a block set up in my main module's build.gradle:

lintOptions {
    <some includes/excludes>

    baseline file("lint-baseline.xml")

    checkAllWarnings true
    warningsAsErrors true
    abortOnError false
}

I then create the baseline with ./gradlew lint<flavor/variant> and have set up my unit test task to depend on lint.

However, this gives a baseline file that includes some absolute paths. The culprits seem to be either a) in a submodule (but only some submodules, not all), or b) in my local gradle cache. When I push the baseline to our CI, it comes up with a bunch of new warnings because the paths don't match exactly.

Some examples include:

<location
        file="/Users/.../android/<submodule>/src/main/res/values/strings.xml"
        line="4"
        column="13"/>

<location
        file="/Users/.../.gradle/caches/modules-2/files-2.1/com.google.auto.value/auto-value/1.3/4961194f62915eb45e21940537d60ac53912c57d/auto-value-1.3.jar"/>

How do I force lint to create the baseline using relative paths?

karl
  • 3,544
  • 3
  • 30
  • 46

2 Answers2

4

use own baseline.xml for each module. paths will be relative to module root directory.

UPDATE try to use only one baseline.xml put put it to the root gradle project above modules like this

project/app/build.gradle
project/module1/build.gradle
project/build.gradle
project/lint-baseline.xml

in module's build.gradle use such snippet

lintOptions {
    baselineFile = rootProject.file('lint-baseline.xml')
}

UPDATE 2 use own baseline.xml for each module. paths will be relative to module root directory. in module's build.gradle use such snippet

lintOptions {
    baselineFile = project.file('lint-baseline.xml')
    checkDependencies = false
}
  • That seems to fix problem a), but not problem b). I'm still getting errors originating in the gradle build cache – karl Dec 05 '17 at 16:50
  • gradle build cache is located outside of your project. you can not use reletive paths for files, localted at build cache – Roman Golov Dec 05 '17 at 17:31
  • this solution is incorrect. lint puts relative paths to files that are not located in current module – Roman Golov Dec 05 '17 at 19:21
  • This unfortunately won't work in a project with multiple module, because lint will abort after creating a baseline, so I end up with the warnings from only one module in the baseline. – karl Dec 05 '17 at 21:29
  • try the first solution but add `checkDependencies false` to your lintOptions – Roman Golov Dec 12 '17 at 12:49
2

Can't you use the absolutePaths option on LintConfig?

android {
  lintOptions {
    absolutePaths false
  }
}
Niklas
  • 23,674
  • 33
  • 131
  • 170