diff --git a/configuration/publishing.gradle b/configuration/publishing.gradle index 9f6c1d1758..2e61fa183d 100644 --- a/configuration/publishing.gradle +++ b/configuration/publishing.gradle @@ -1,5 +1,6 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2013 Chris Banes + * Modifications copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -13,13 +14,16 @@ * permissions and limitations under the License. */ -apply plugin: 'maven' apply plugin: 'signing' apply plugin: 'maven-publish' version = project.ext.VERSION_NAME group = POM_GROUP +def isReleaseBuild() { + return VERSION_NAME.contains("SNAPSHOT") == false +} + def getReleaseRepositoryUrl() { return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL : "https://aws.oss.sonatype.org/service/local/staging/deploy/maven2/" @@ -39,215 +43,113 @@ def getRepositoryPassword() { } afterEvaluate { project -> - uploadArchives { - repositories { - if (project.hasProperty('SONATYPE_NEXUS_USERNAME')) { - mavenDeployer { - beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } - - pom.groupId = POM_GROUP - pom.artifactId = POM_ARTIFACT_ID - pom.version = project.ext.VERSION_NAME - - repository(url: getReleaseRepositoryUrl()) { - authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) - } - snapshotRepository(url: getSnapshotRepositoryUrl()) { - authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) - } - - 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 - } + task androidJavadocs(type: Javadoc) { + failOnError false + source = android.sourceSets.main.java.source + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + } - licenses { - license { - name POM_LICENCE_NAME - url POM_LICENCE_URL - distribution POM_LICENCE_DIST - } - } + afterEvaluate { + androidJavadocs.classpath += files(android.libraryVariants.collect { variant -> + variant.javaCompileProvider.get().classpath.files + }) + } - developers { - developer { - id POM_DEVELOPER_ID - organizationUrl POM_DEVELOPER_ORGANIZATION_URL - roles { - role "developer" - } - } - } - } - } - } else { - mavenInstaller { - pom.groupId = POM_GROUP - pom.artifactId = POM_ARTIFACT_ID - pom.version = project.ext.VERSION_NAME - } - } - } + task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { + classifier = 'javadoc' + from androidJavadocs.destinationDir } - signing { - required { - project.ext.VERSION_NAME.contains("SNAPSHOT") == false && - gradle.taskGraph.hasTask("uploadArchives") - } - if (project.hasProperty('signing.inMemoryKey')) { - def signingKey = findProperty("signing.inMemoryKey").replace("\\n","\n") - def signingPassword = findProperty("signing.password") - def keyId = findProperty("signing.keyId") - useInMemoryPgpKeys(keyId, signingKey, signingPassword) - } - sign configurations.archives + task androidSourcesJar(type: Jar) { + classifier = 'sources' + from android.sourceSets.main.java.source } - if (project.getPlugins().hasPlugin('com.android.application') || - project.getPlugins().hasPlugin('com.android.library')) { - task install(type: Upload, dependsOn: assemble) { - repositories.mavenInstaller { - configuration = configurations.archives - pom.groupId = POM_GROUP - pom.artifactId = POM_ARTIFACT_ID - pom.version = project.ext.VERSION_NAME + publishing { + publications { + library(MavenPublication) { + groupId POM_GROUP + artifactId POM_ARTIFACT_ID + version VERSION_NAME + + artifact("${buildDir}/outputs/aar/${artifactId}-release.aar") - pom.project { - name POM_NAME - packaging POM_PACKAGING - description POM_DESCRIPTION - url POM_URL + pom { + 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 + 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 + name = POM_LICENSE_NAME + url = POM_LICENSE_URL + distribution = POM_LICENSE_DIST } } developers { developer { - id POM_DEVELOPER_ID - organization POM_DEVELOPER_ORGANIZATION - organizationUrl POM_DEVELOPER_ORGANIZATION_URL - } - } - } - } - } - - task androidJavadocs(type: Javadoc) { - failOnError false - source = android.sourceSets.main.java.source - classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) - } - - afterEvaluate { - androidJavadocs.classpath += files(android.libraryVariants.collect { variant -> - variant.javaCompileProvider.get().classpath.files - }) - } - - task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { - classifier = 'javadoc' - from androidJavadocs.destinationDir - } - - task androidSourcesJar(type: Jar) { - classifier = 'sources' - from android.sourceSets.main.java.source - } - } else { - install { - repositories.mavenInstaller { - pom.groupId = POM_GROUP - pom.artifactId = POM_ARTIFACT_ID - pom.version = project.ext.VERSION_NAME - - 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 + id = POM_DEVELOPER_ID + organizationUrl = POM_DEVELOPER_ORGANIZATION_URL + roles = ["developer"] } } - developers { - developer { - id POM_DEVELOPER_ID - organization POM_DEVELOPER_ORGANIZATION - organizationUrl POM_DEVELOPER_ORGANIZATION_URL + withXml { + def dependenciesNode = asNode().appendNode('dependencies') + // Note that this only handles implementation + // dependencies. In the future, may need to add api, + // etc. + configurations.implementation.allDependencies.each { + def dependencyNode = dependenciesNode.appendNode('dependency') + dependencyNode.appendNode('groupId', it.group) + dependencyNode.appendNode('artifactId', it.name) + dependencyNode.appendNode('version', it.version) } } } } } + repositories { + maven { + url = isReleaseBuild() ? getReleaseRepositoryUrl() : getSnapshotRepositoryUrl() + credentials { + username = getRepositoryUsername() + password = getRepositoryPassword() + } + } + } + } - task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource + + signing { + required { isReleaseBuild() && gradle.taskGraph.hasTask("publish") } + if (project.hasProperty('signing.inMemoryKey')) { + def signingKey = findProperty("signing.inMemoryKey").replace("\\n", "\n") + def signingPassword = findProperty("signing.password") + def keyId = findProperty("signing.keyId") + useInMemoryPgpKeys(keyId, signingKey, signingPassword) } + sign publishing.publications.library } + artifacts { if (project.getPlugins().hasPlugin('com.android.application') || - project.getPlugins().hasPlugin('com.android.library')) { + project.getPlugins().hasPlugin('com.android.library')) { archives androidSourcesJar archives androidJavadocsJar } else { archives sourcesJar } } - - publishing { - publications { - library(MavenPublication) { - groupId POM_GROUP - artifactId POM_ARTIFACT_ID - version project.ext.VERSION_NAME - artifact("${buildDir}/outputs/aar/${artifactId}-release.aar") - pom.withXml { - def dependenciesNode = asNode().appendNode('dependencies') - // Note that this only handles implementation - // dependencies. In the future, may need to add api, - // etc. - configurations.implementation.allDependencies.each { - def dependencyNode = dependenciesNode.appendNode('dependency') - dependencyNode.appendNode('groupId', it.group) - dependencyNode.appendNode('artifactId', it.name) - dependencyNode.appendNode('version', it.version) - } - } - } - } - } } diff --git a/gradle.properties b/gradle.properties index f8678fd73d..4e88c028e0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,9 +20,9 @@ POM_SCM_URL=https://github.com/aws-amplify/amplify-android POM_SCM_CONNECTION=scm:git:git://github.com/aws-amplify/amplify-android.git POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/aws-amplify/amplify-android.git -POM_LICENCE_NAME=Apache 2.0 -POM_LICENCE_URL=http://aws.amazon.com/apache2.0 -POM_LICENCE_DIST=repo +POM_LICENSE_NAME=Apache 2.0 +POM_LICENSE_URL=http://aws.amazon.com/apache2.0 +POM_LICENSE_DIST=repo POM_DEVELOPER_ID=amazonwebservices POM_DEVELOPER_NAME=amazonwebservices diff --git a/scripts/maven-release-publisher.yml b/scripts/maven-release-publisher.yml index 91696496d4..e0c83e1342 100644 --- a/scripts/maven-release-publisher.yml +++ b/scripts/maven-release-publisher.yml @@ -4,8 +4,8 @@ env: secrets-manager: ORG_GRADLE_PROJECT_SONATYPE_NEXUS_USERNAME: awsmobilesdk/android/sonatype:username ORG_GRADLE_PROJECT_SONATYPE_NEXUS_PASSWORD: awsmobilesdk/android/sonatype:password - ORG_GRADLE_PROJECT_signingPassword: awsmobilesdk/android/signing:password - ORG_GRADLE_PROJECT_signingKeyId: awsmobilesdk/android/signing:keyId + ORG_GRADLE_PROJECT_signingPassword: awsmobilesdk/android/signing:password + ORG_GRADLE_PROJECT_signingKeyId: awsmobilesdk/android/signing:keyId ORG_GRADLE_PROJECT_signingInMemoryKey: awsmobilesdk/android/signing:inMemoryKey phases: install: @@ -23,9 +23,9 @@ phases: - echo 'Build phase starting.' - | # List all available gradle tasks, grep for the uploadArchive tasks, and then use cut to strip the - # task description and just return the name of the task, one for each module (e.g. aws-api:uploadArchives) + # task description and just return the name of the task, one for each module (e.g. aws-api:publish) JAVA_HOME=$JDK_8_HOME ./gradlew clean build - for task_name in $(./gradlew tasks --all | grep uploadArchives | cut -d " " -f 1); do + for task_name in $(./gradlew tasks --all | grep ":publish " | cut -d " " -f 1); do echo "Gradle task $task_name" JAVA_HOME=$JDK_8_HOME ./gradlew $task_name; done