Multi Module Gradle Project as Library

Viewed 206

I have a multi module gradle project that I want to use as a library. It looks as follows:

parent
|
|---child1
|
|---child2
|
|---child3

The modules are implemented via implementation project(':childX') in the parents build.gradle file

Everything works fine when building the library project. I add all the compiled classes of all child-modules to the parent jar.

But when I try to add the library into another project, I get errors because gradle cannot find the child-module-dependencies jars:

Could not find de.example:child1-1.0.0.
Required by:
    project : > de.example:parent:1.0.0

How can I make this work in my project? I have researched for hours but cannot seem to find a case where someone did this. What I don't want is to publish all child-modules as separate jars and include them directly from the repository. I want to have the child-modules inside the parent-module.

Here is my build.gradle from my parent-module:

apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.artifactory'

group = 'de.example'
version = "${currentVersion}"
sourceCompatibility = 1.8

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
            artifactId = 'parent'
        }
    }
}

artifactory {
    contextUrl = "${artifactory_url}"
    publish {
        repository {
            repoKey = 'gradle-release-local'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
        }
        defaults {
            publications ('mavenJava')
            publishArtifacts = true
        }
    }
}

jar {
    archivesBaseName = 'parent'
    subprojects.each { subproject ->
        from subproject.configurations.archives.allArtifacts.files.collect {
            zipTree(it)
        }
    }
    dependsOn subprojects.jar
}

artifacts {
    archives jar
}

dependencies {
    implementation project(':child1')
    implementation project(':child2')
    implementation project(':child3')
}
0 Answers
Related