Skip to content

ABI filtering

Tony Robalik edited this page May 30, 2022 · 2 revisions

v0.42.0 adds a new feature to the extension DSL.

ABI Exclusions

root build.gradle
dependencyAnalysis {
  abi {
    exclusions {
      // Convenience helpers
      ignoreSubPackage("internal")
      ignoreInternalPackages()
      ignoreGeneratedCode()

      // Raw, regexp-based APIs
      excludeAnnotations(".*\\.Generated")
      excludeClasses(".*\\.internal\\..*")
    }
  }
}

To understand what this means, consider the following scenario.

com/example/Example.kt
package com.example.Example

import com.some.Thing

class Example {
  fun thing(): Thing {
    return Thing()
  }
}

Where Example is a class in a library* at com.example:library:1.0, and Thing is provided by library com.some:thing:1.0. Thing is part of the ABI (binary API) of com.example:library, because it is exposed as a return type in a public function in a public class.

* it’s important that this is a library because applications have no logical ABI whatsoever.

Given this scenario, if the build script for com.example:library contains

library/build.gradle
dependencies {
  implementation "com.some:thing:1.0"
}

then the plugin will tell you that you should change that dependency to api.

Now consider:

root build.gradle
dependencyAnalysis {
  abi {
    exclusions {
      excludeClasses("com\\.example\\.Example")
    }
  }
}

(Recalling this takes a regex.) Now if we run buildHealth again, the plugin will no longer suggest that com.some:thing:1.0 be api.