androidkotlingradlegradle-kotlin-dsl

implementation passthrough from library in kotlin dsl


I can't figure out how to let my library pass another library to a main app. I know that sounds a little weird, so I'll try to explain the best I can. For a simple example, I have an annotation processor that I built that makes code generation much easier. I also have a library to hold UI elements and common functionality. In order to kind of package them together I went into my library gradle dsl file and added an implementation on the annotation processor...

library gradle file...

//... gradle file
dependencies {
  //... dependencies
  implementation(libs.annotations)
  kapt(libs.annotations)
  //... dependencies
}
//.. rest of gradle file

Then in my sample app that I am using to test all of this I am adding a dependency on the library

dependencies {
  implementation(libs.library)
}

However in my code when I try to annotate a class with my annotation I am getting an error unresolved reference 'annotations'

Is there a way to allow my library to also provide my annotations?

If it matters I compile the library to an aar and then upload it to a private artifactory repo, which is then added to my sample app.


Solution

  • Replace:

    implementation(libs.annotations)
    

    with:

    api(libs.annotations)
    

    api() says "expose this library's public API as part of my library's public API". implementation() says "use this library, but do not make it available my library's consumers".