Pack a multi-module Gradle library into a single module

Ant*_*on3 5 gradle multi-module kotlin

I've split my pancakes Gradle-based library written in Kotlin into multiple modules: pancakes-core, pancakes-addon1, ..., pancakes-addonN. The addon ones include the core one.

Now, most users shouldn't care and will just want the default configuration with all the dependencies included. But they will have to write boilerplate:

dependencies {
    implementation("pancakes:pancakes-core")
    implementation("pancakes:pancakes-addon1")
    ...
    implementation("pancakes:pancakes-addonN")
}
Run Code Online (Sandbox Code Playgroud)

This is a no-go for me. I'll probably have to merge all the modules, although I've just spent some time to branch off some replaceable features into their own modules.

Unless! There is a way to write something like the following:

project(":pancakes-simple") {
    dependencies {
        autoForwardedApi(":pancakes-core")
        autoForwardedApi(":pancakes-addon1")
        ...
        autoForwardedApi(":pancakes-addonN")
    }
}
Run Code Online (Sandbox Code Playgroud)

Unfortunately, api is not enough.

Ant*_*on3 2

java-libraryapi要从当前模块转发依赖项,需要 Gradle 插件。这就是如何将所有模块打包到一个模块中:

  1. 在库的所有模块中添加java-library插件(并删除)java
  2. :pancakes-simple创建一个像我这样的模块 -api依赖于所有其他模块