1

I'm trying to publish a multi-module library but I only want to publish only want one module as follows:

-module main
-module data
-module domain

enter image description here

Sample app should implement only main module (as this is the gate of the library)

BUT main module depends on data and domain modules

At first I was using implementation (project(":data/domain"))

implementation(project(":domain"))
implementation(project(":data"))

but when I tried to publish the main module (maven local for now) and use the main artifact in the sample app I got the error message that data and domain dependencies could not be found.

I had to publish data and domain for it to be found despite declaring them as implementation project

What am I doing wrong? I can't believe we need to publish all of the modules of a library for the main module to be usable by an app...

asked Aug 14, 2024 at 15:49

1 Answer 1

2
+400

So Maven, either local or global, depends on declaring dependencies in POM format XML files. Even if you publish with Gradle or any other tool, it will always build pom.xml files for the modules you want to publish because that is how Maven works.

That means that the Maven itself is limited by the POM protocol. Knowing that we can safely assume all the dependencies declared in the pom.xml generated via publishing the library would comply with the POM dependencies rules.

If you read through them, you'll notice that there is no way to include any dependency that is not published into the library except for the system dependency scope, which can only be a precompiled JAR file. So, any modules your library depends on that are not compiled should be properly published into Maven. Or be precompiled JAR files. There is no gray area.

That means you should either publish all the modules of your multimodular project or compile them into jars and import them accordingly. There is no way around that.

answered Aug 19, 2024 at 10:04
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer, that totally answers to my question. Actually I also tried to build the JAR/AAR of other modules but I got a no "NoClassFound" when referring to the class of the JAR/AAR but I probably was doing something wrong

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.