3

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.

Chee-Yi
  • 880
  • 10
  • 17
  • How do you import lib? You shouldn't build doc (and then the mokka requirement) if you are working on the app and not the lib. – Gabriele Mariotti Aug 22 '19 at 10:49
  • @GabrieleMariotti My `lib` module is imported by specifying the path to it in `settings.gradle` then I include it as a dependency in my `app` level `build.gradle`. The thing is that the `apply plugin: 'org.jetbrains.dokka-android'` part in the `lib`'s `build.gradle` is complaining that it couldn't find the plugin. – Chee-Yi Aug 22 '19 at 13:17

1 Answers1

2

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.
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • 2
    Thanks, this was it! I wasn't aware that we can have `buildscript` blocks in module-level `build.gradle` files. – Chee-Yi Aug 23 '19 at 04:59