简体   繁体   中英

Consumer of Android library module having to add classpath dependencies

I have an Android app ( app module) and an Android library module ( lib module), each being a separate Android Studio project, but the app project added lib in as a module dependency in its project.

The lib uses JetBrain's Dokka to generate HTML documentation, and it needs the Dokka Android Gradle plugin, which is defined in its own project's top-level build.gradle :

buildscript {
    dependencies {
        // ...
        classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:0.9.18"
    }
}

And in the lib module's build.gradle I had to add the following

apply plugin: 'org.jetbrains.dokka-android'

android {
    // ...
    dokka { /* my Dokka config */ }
}

So right now the lib project works and builds fine and I'm able to generate documentation HTMLs using Dokka.

However, my app project's Gradle sync now fails because it says "Plugin with id org.jetbrains.dokka-android not found". If I add the classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:0.9.18" to my app project's top-level build.gradle then it works fine.

My question is, how do I tell the main (app) project that the classpath dependency for Dokka has already been declared in the lib module's top-level build.gradle ? Or is there a way to specify this dependency for just the lib module? I also think it's weird if I have multiple apps using my lib module and they would need to add this classpath dependency to be able to build their apps.

Much thanks.

You can just add this part in your lib/build.gradle removing from the top-level file.

buildscript {
    //
    dependencies {
        classpath 'org.jetbrains.dokka:dokka-android-gradle-plugin:0.9.18'
    }
}

It happens because you are importing this lib as an external module and you are running some tasks (for example a build task) in the lib module.
You can avoid it:

  • import your lib as an aar or a maven dependency (best option is to publish in a private maven repo)
  • just run tasks related to the app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM