0

I have a Gradle 6.5 project bar that has several subprojects and uses split packages, which I cannot remove in the current configuration.

I want to package an additional bar-all artifact that declares an automatic module name via MANIFEST.MF

Automatic-Module-Name: com.foo.bar

and contains all the classes from all the subprojects. The main purpose of this additional artifact is for use in modular applications and to avoid the split package problem.

I suspect I need to take the build outputs of the other subprojects and reuse them in a custom Jar task within bar-all but can't find a good example of this.

kittylyst
  • 5,640
  • 2
  • 23
  • 36
  • „*…The main purpose of this additional artifact is…to avoid the split package problem…*“— [*I solved another split package problem recently*](https://stackoverflow.com/questions/64072627/understanding-errors-with-jpms-modules/64124282#64124282). I'm late to the party. So I presume you will have already found a solution by now. But if you're interested anyway, I could help you apply that same plugin to an [*MRE*](https://stackoverflow.com/help/minimal-reproducible-example) that you push to a repo. – deduper Oct 03 '20 at 19:07

1 Answers1

0

for a sample structure below, where top project is dependent on all sub projects - so top builds the uber jar

top 
 |___spa
 |___spb
 |___spc
 |___spd
 |___spe

settings.gradle

rootProject.name = 'top'

include 'spa', 'spb', 'spc', 'spd', 'spe'

build.gradle

dependencies {
    implementation project('spa')
    implementation project('spb')
    implementation project('spd')
    implementation project('spe')

    implementation 'com.google.guava:guava:28.1-jre'
}

task jarAll(type: Jar, dependsOn: jar) {
    archiveClassifier = 'all'
    from sourceSets.main.output
    dependsOn configurations.runtimeClasspath
    from {
        configurations.runtimeClasspath.allDependencies.findAll { it instanceof ProjectDependency }.collect { it.dependencyProject.sourceSets.main.output }
    }
    manifest {
        attributes (
            "Automatic-Module-Name": "com.foo.bar" )
    }
}

the top-all.jar will include the classes from the sub-projects;

PrasadU
  • 2,154
  • 1
  • 9
  • 10
  • Some of this (e.g. configurations.runtimeClasspath.allDependencies) appears to be deprecated / unavailable in Gradle 6. I'm using a Kotlin build script though, so it's possible I'm not transliterating it into Kotlin properly, though. – kittylyst Jul 22 '20 at 09:10