Combine multiple projects into one archive for uploadArchives


(Niek Haarman) #1

I’d like to split up a module (‘library’) in two modules (‘lib-core’) and (‘lib-extras’).

Currently, I’m publishing with artifact id ‘library’, and I want to keep this functionality as well. I also want to publish the two separate modules.

For example:

  • lib-core
  • class A
  • lib-extras
  • class B
  • library

(empty, depends on lib-core and lib-extras)

What I want to achieve is when publishing these modules, I get an archive ‘lib-core’ containing class ‘A’, and archive ‘lib-extras’ containing class ‘B’, and an archive ‘library’, containing both classes ‘A’ and ‘B’.

Is this possible using gradle?

This is my uploadArchives task, which is applied in all three modules:

apply plugin: 'maven'
    apply plugin: 'signing'
          def sonatypeRepositoryUrl
    if (isRelease == 'true') {
        sonatypeRepositoryUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
        println 'RELEASE BUILD ' + version
    } else {
        sonatypeRepositoryUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
        version = VERSION_NAME + '-SNAPSHOT'
        println 'DEBUG BUILD ' + version
    }
          afterEvaluate { project ->
        uploadArchives {
            repositories {
                mavenDeployer {
                    beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
                          pom.artifactId = POM_ARTIFACT_ID
                          repository(url: sonatypeRepositoryUrl) {
                        authentication(userName: nexusUsername, password: nexusPassword)
                    }
                          pom.project {
                        name POM_NAME
                        packaging POM_PACKAGING
                        description POM_DESCRIPTION
                        url POM_URL
                              scm {
                            url POM_SCM_URL
                            connection POM_SCM_CONNECTION
                            developerConnection POM_SCM_DEV_CONNECTION
                        }
                              licenses {
                            license {
                                name POM_LICENCE_NAME
                                url POM_LICENCE_URL
                                distribution POM_LICENCE_DIST
                            }
                        }
                              developers {
                            developer {
                                id POM_DEVELOPER_ID
                                name POM_DEVELOPER_NAME
                            }
                        }
                    }
                }
            }
        }
              signing {
            required { isRelease == 'true' && gradle.taskGraph.hasTask("uploadArchives") }
            sign configurations.archives
        }
              task androidJavadocs(type: Javadoc) {
            source = android.sourceSets.main.java
        }
              task androidJavadocsJar(type: Jar) {
            classifier = 'javadoc'
            from androidJavadocs.destinationDir
        }
              task androidSourcesJar(type: Jar) {
            classifier = 'sources'
            from android.sourceSets.main.java.sourceFiles
        }
              artifacts {
            archives androidSourcesJar
            archives androidJavadocsJar
        }
    }