multi module gradle project - grouping sub-projects under a parent

Viewed 1392

I have been trying to create a multimodule gradle project, I have referred to these link apart from a few others

I was able to create multiple modules and execute multiple commands for all modules and for specific modules using root level gradle wrapper, something like ./gradlew :java-libs:payment-lib:build works.

I am also publishing these libraries to a nexus repository that acts as an internal maven repository. This is what my root build.gradle looks like:

apply plugin: 'base'

subprojects {
    apply plugin: 'java'
    apply plugin: 'maven-publish'

    publishing {
        publications {
            maven(MavenPublication) {
                artifact("build/libs/$project.name-$version" + ".jar") {
                    extension 'jar'
                }
            }
            mavenJava(MavenPublication) {
                from components.java
            }
        }

        repositories {
            maven {
                name 'nexus'
                url "<nexus_url>/repository/maven-snapshots/"
                credentials {
                    username nexusUsername
                    password nexusPassword
                }
            }
        }
    }
}

This enables me to publish any or all modules to nexus from the root gradlew, and I don't have to write the publications section in each module again and again.

What I want to achieve

As of now each module is treated as a separate project in nexus, with its own versioning, its own folder, and when 2 of these modules need to be imported in a different project, I need to include 2 statements that are unrelated to each other.

compile("com.something.payment-lib:0.3-SNAPSHOT")
compile("com.something.refund-lib:0.2-SNAPSHOT")

I have been using some external libraries where I was able to do something like this:

compile("org.apache.httpcomponents:httpclient:4.5.12"){
    exclude(module: 'commons-logging')
}

Which suggests that all modules within the multi-module gradle project are under a single group org.apache.httpcomponents:httpclient, which also has a version of its own. And I can include/exclude specific modules within that group.
I tried looking at its code, but it is using maven and the config looks quite different.

I also don't know even if I am able to achieve such a grouping, what will the folder structure look like inside the nexus repository. Would there be a folder for the project and then there would be sub-folders with the jars of the respective modules?

1 Answers
Related