How to publish apks to the Maven Central with gradle?


(snowdream) #1

I create an android project with android studio.

It will generate some apks.

How can i publish apks to the Maven Central with gradle?

What can i write in the artifacts for the apk?

https://gist.github.com/snowdream/7355194
apply plugin: 'maven'
apply plugin: 'signing'
  configurations {
    archives {
        extendsFrom configurations.default
    }
}
  def sonatypeRepositoryUrl
if (isReleaseBuild()) {
    println 'Sonatype RELEASE BUILD'
    sonatypeRepositoryUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
} else {
    println 'Sonatype SNAPSHOT BUILD'
    sonatypeRepositoryUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
}
  def githubRepositoryUrl
if (isReleaseBuild()) {
    println 'GITHUB RELEASE BUILD'
    githubRepositoryUrl = "file:///home/snowdream/workspace/git/mvn-repo/releases"
} else {
    println 'GITHUB SNAPSHOT BUILD'
    githubRepositoryUrl = "file:///home/snowdream/workspace/git/mvn-repo/snapshots"
}
  if (ext.properties.containsKey('signing.keyId') &&
        !ext.properties.containsKey('signing.password')) {
    if (System.console()) {
        ext.set('signing.password',
                System.console().readPassword("\n\$ Type in GPG key password: "))
    } else {
        ext.set('signing.password', 'snowdream')
    }
}
  if (!ext.properties.containsKey('nexusUsername')) {
    if (System.console()) {
        ext.set('nexusUsername', new String(System.console().readPassword(
                "\n\$ Type in username for Sonatype nexus account ${nexusUsername}: ")))
    } else {
        ext.set('nexusUsername', 'snowdream')
    }
}
  if (!ext.properties.containsKey('nexusPassword')) {
    if (System.console()) {
        ext.set('nexusPassword', new String(System.console().readPassword(
                "\n\$ Type in password for Sonatype nexus account ${nexusUsername}: ")))
    } else {
        ext.set('nexusPassword', 'snowdream')
    }
}
  afterEvaluate { project ->
    uploadArchives {
        repositories {
            mavenDeployer {
                configurePOM(pom)
                beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
                  repository(url: sonatypeRepositoryUrl) {
                    authentication(userName: nexusUsername, password: nexusPassword)
                }
            }
              mavenDeployer {
                configurePOM(pom)
                beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
                  repository(url: githubRepositoryUrl)
            }
        }
    }
      signing {
        required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
        sign configurations.archives
    }
      task androidReleaseJar(type: Jar, dependsOn: assembleRelease) {
        from "$buildDir/classes/release/"
    }
      task androidJavadocsJar(type: Jar) {
        classifier = 'javadoc'
        from generateReleaseJavadoc.destinationDir
    }
      task androidSourcesJar(type: Jar) {
        classifier = 'sources'
        from android.sourceSets.main.allSource
    }
        artifacts {
        archives file: files(dir: '$buildDir/apk/*.apk', include: '*.apk')
        archives androidReleaseJar
        archives androidSourcesJar
        archives androidJavadocsJar
    }
}
  private configurePOM(def pom) {
    pom.project {
        groupId POM_GROUP_ID
        artifactId POM_ARTIFACT_ID
        version POM_VERSION
        name POM_NAME
        packaging POM_PACKAGING
        description POM_DESCRIPTION
        url POM_URL
        inceptionYear POM_INCEPTION_YEAR
          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
                comments POM_LICENCE_COMMENTS
            }
        }
          developers {
            developer {
                id POM_DEVELOPER_ID
                name POM_DEVELOPER_NAME
                email POM_DEVELOPER_EMAIL
                url POM_DEVELOPER_URL
            }
        }
          issueManagement {
            system POM_ISSUE_MANAGEMENT_SYSTEM
            url POM_ISSUE_MANAGEMENT_URL
        }
    }
}

(snowdream) #2

any idea?