Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Remove deprecated maven plugin #2137

Merged
merged 3 commits into from Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
248 changes: 75 additions & 173 deletions configuration/publishing.gradle
@@ -1,5 +1,6 @@
/*
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2013 Chris Banes
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This attribution was missing for the original author

* 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.
Expand All @@ -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/"
Expand All @@ -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)
}
}
}
}
}
}

6 changes: 3 additions & 3 deletions gradle.properties
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions scripts/maven-release-publisher.yml
Expand Up @@ -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:
Expand All @@ -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
Expand Down