Multiproject publish

I have a multiproject project where the toplevel project has no code. The subprojects produce a jar. The toplevel project zips all jars from subprojects into a distribution zip. All jars are using one global version.

I am trying to support these 2 usecases:

  1. Developer changed code. Subproject jars should be built and published to local maven repo (%USERPROFILE%.m2\repository)
  2. Build subproject jars, zip them into a distribution zip and publish it to an external repo.

I created a small test project to show this:

Usecase 2 works fine when I run gradlew publishReleasePublicationToReleasesRepository
For usecase 1 I wanted to define a publication that included the jars from all the subprojects, but I can’t seem to get that to work:

publishing {
    publications {
        release(MavenPublication) {
            artifactId 'testapplication'
            artifact distZip
        }
//      integrations(MavenPublication) {
//          artifact subprojects.jar
//      }
    }
    repositories {
        maven {
            name 'releases'
            url "file://$projectDir/../release-repo"
        }
    }
}

Any suggestions how to get this to work? Am I thinking about this all wrong?

I found a solution. I created one publish block for the top level project that publishes the distribution zip and another publish block for all subprojects that publish their own artifact.

toplevel:

publishing {
    publications {
        release(MavenPublication) {
            artifactId 'testapplication'
            artifact distZip
        }
    }
    repositories {
        maven {
            name 'releases'
            url "file://$projectDir/../release-repo"
        }
    }
}

// Alias for the task publishReleasePublicationToReleasesRepository that publishes the distribution zip to the release repo
task publishRelease(dependsOn: 'publishReleasePublicationToReleasesRepository') {}

subprojects:

subprojects {
    apply plugin: 'java'
    apply plugin: 'osgi'

    //noinspection GroovyUnusedAssignment
    sourceCompatibility = JavaVersion.VERSION_1_8

    dependencies {
        testCompile group: 'junit', name: 'junit', version: '4.11'
    }

    publishing {
        publications {
            beta(MavenPublication) {
                from components.java
            }
        }
    }

    // Alias for the task publishBetaPublicationToMavenLocal that publishes the individual integration jars to the local Maven repo
    task install(dependsOn: 'publishBetaPublicationToMavenLocal') {}
}

I can then use gradlew install for use case 1 and gradlew publishRelease for use case 2