cordova-android/framework/cordova-publish.gradle
Darryl Pogue 80f232aa79
fix: correctly flag API dependency on AppCompat for Maven (#1505)
* Correctly flag API dependency on AppCompat for Maven

Currently when cordova-android is published to Maven, it lists no
dependencies. However, `CordovaActivity` extends `AppCompatActivity`
which requires that the AndroidX AppCompat library be available.

Marking this as an API dependency (rather than an implementation/compile
dependency) should cause the AndroidX AppCompat library to be installed
when the cordova-android framework is added to the build.gradle of an
existing Android application.

* Publish to Maven with proper metadata

This allows the Maven publish to pick up information from the android
library component and include things like dependencies in the pom.xml
file.
2022-10-15 13:39:47 +09:00

122 lines
4.7 KiB
Groovy

/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
apply plugin: 'maven-publish'
apply plugin: 'signing'
String getCordovaAndroidVersion() {
// Fetch Data from Cordova-Android package.json (Used only by framework build/publishing)
def cordovaAndroidRepoPackageJson = "$projectDir/../package.json"
if(file(cordovaAndroidRepoPackageJson).exists()) {
def packageJsonFile = new File(cordovaAndroidRepoPackageJson)
def packageJson = new groovy.json.JsonSlurper().parseText(packageJsonFile.text)
return packageJson.version
}
}
// Enable signing by default when keyId and secretKeyRingFile is defined.
ext.cdvEnableSigning = project.hasProperty('signing.keyId') && project.hasProperty('signing.secretKeyRingFile')
if (cdvEnableSigning) {
logger.debug('[Cordova] Signing has been enabled by default because the signing keyId & secretKeyRingFile has been defined.')
}
if (project.hasProperty('signEnabled')) {
if(!cdvEnableSigning && Boolean.valueOf(signEnabled)) {
logger.debug("[Cordova] The \"signEnabled\" override can not be set to \"true\" when the signing properties are missing.")
} else {
// Override the default setting with the "signEnabled" property. (In this case it should only accept false)
logger.debug("[Cordova] The \"signEnabled\" property has been detected and forcing enabled signing to \"$signEnabled\".")
cdvEnableSigning = signEnabled
}
}
afterEvaluate {
publishing {
publications {
mavenJava(MavenPublication) {
groupId = 'org.apache.cordova'
artifactId = 'framework'
version = getCordovaAndroidVersion()
from components.release
pom {
name = 'Cordova'
description = 'A library to build Cordova-based projects for the Android platform.'
url = 'https://cordova.apache.org'
licenses {
license {
name = 'Apache License, Version 2.0'
url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'stevengill'
name = 'Steve Gill'
}
developer {
id = 'erisu'
name = 'Bryan Ellis'
email = 'erisu@apache.org'
}
}
scm {
connection = 'scm:git:https://github.com/apache/cordova-android.git'
developerConnection = 'scm:git:git@github.com:apache/cordova-android.git'
url = 'https://github.com/apache/cordova-android'
}
}
}
}
repositories {
maven {
def releasesRepoUrl = 'https://repository.apache.org/content/repositories/releases'
def snapshotsRepoUrl = 'https://repository.apache.org/content/repositories/snapshots'
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
credentials {
if (project.hasProperty('apacheUsername') && project.hasProperty('apachePassword')) {
username apacheUsername
password apachePassword
}
}
}
}
signing {
if (Boolean.valueOf(cdvEnableSigning)) {
sign publishing.publications.mavenJava
}
}
}
}
tasks.whenTaskAdded {task ->
if(task.name.contains('sign')) {
logger.debug("[Cordova] The task \"${task.name}\" is enabled? ${cdvEnableSigning}")
task.enabled = cdvEnableSigning
}
}