Hi, is there any tutorial on how to work with mult...
# getting-started
a
Hi, is there any tutorial on how to work with multiple gradle modules ?
t
Yes, I would look at Gradle’s documentation itself
there are not many specifics for Kotlin gradle modules.
what are you trying to accomplish?
a
I have a Kotlin/JS library that gives typings to a JavaScript library, but this JavaScript library has many optional dependencies and plugins, so I want to set typings also into other modules, but I've never used multiple modules for a project before
t
Basically you make a new folder for the second module, set it up pretty much like the first, and when one needs to depend on the other you use
implementation(project(":projectName"))
instead of a maven dependency
If your current module is the root module, I suggest moving that into a subfolder first so they are siblings rather than parent-child
a
Thanks ! Also, the JavaScript library has like 20 optional plugins (I've just done typings for 6 of them), do I really need to have all these folders in my project or won't it be cleaner to have a directory for all these ?
t
Depends how you want to bundle them. If you want them all bundled separately, you need a separate folder for each
a
No I mean like a
plugins
folder with all modules inside
t
Sorry I’m not following, what is in this folder? The JS modules?
If you have a 1:1 relationship with the JS plugin to the KT typing/gradle module then I would expect each gradle module to have the JS plugin it depends on in it’s folder
a
I mean like this file tree:
Copy code
/buildSrc
  build.gradle.kts
/gradle
/main-module
  build.gradle.kts
/plugins
  /plugin1
    build.gradle.kts
  /plugin2
    build.gradle.kts
  /plugin3
    build.gradle.kts
build.gradle.kts
gradle.properties
...
t
Yes you can do that.
if plugin 1 needs to depend on plugin 2, then plugin 1 does
implementation(project(":plugins:plugin2")
if plugin 1 depends on main-module then you can do
implementation(project(":main-module"))
a
okay I see, thanks I'll try !
t
If you don’t want the
:plugins
prefix you can get around it with the settings.gradle.kts file. But I’ll save my breath unless you really want to do that
a
Yeah I don't need that
1
Also, publishing should be kept at root
build.gradle.kts
? But then how can I target a jar to be published from a specific module ?
t
you would have a publishing plugin and task on each submodule
but if you like the root can call all the publish tasks
a
I guess that signing and nexusPublishing should be kept at root as it will be the exact same thing for each modules ?
t
sharing config across gradle modules is a huge topic worthy of it’s own discussion
The naive way to do it is use allprojects in the root gradle file. It’s not performant, but it works.
It breaks configuration avoidance which means gradle will configure all your modules, even if you only want to build one.
a
I'm having
Projects must be configuring
error in each submodule no matter what I try :/
t
Try settling with the duplication for now. Apply the publishing Gradle plugin and configure it in each and every submodule.
It's not pretty but it will rule out some other issues
a
Oh, I was just having a dependency not found, fixed it and everything working now x)