react-native/ReactAndroid/release.gradle

134 lines
3.7 KiB
Groovy
Raw Normal View History

// Copyright 2015-present Facebook. All Rights Reserved.
apply plugin: 'maven'
apply plugin: 'signing'
// Gradle tasks for publishing to maven
// 1) To install in local maven repo use :installArchives task
// 2) To upload artifact to maven central use: :uploadArchives (you'd need to have the permission to do that)
def isReleaseBuild() {
return VERSION_NAME.contains('SNAPSHOT') == false
}
def getRepositoryUrl() {
Update ReactAndroid build script to support gradle 2.3.0 Summary: We updated to Gradle 2.3.0 and our app's build failed. Our app doesn't provide "repositoryUrl" which is intended to be an optional gradle property. However, Gradle 2.3.0 blows up on findProperty('repositoryUrl') when "repositoryUrl" isn't provided: ```` * What went wrong: A problem occurred configuring project ':ContextMenuAndroid'. > Could not resolve all dependencies for configuration ':ContextMenuAndroid:_debugPublish'. > A problem occurred configuring project ':ReactAndroid'. > Could not get unknown property 'repositoryUrl' for project ':ReactAndroid' of type org.gradle.api.Project. ```` To fix this, we now use "project.hasProperty('repositoryUrl')" to safely detect the presence of the optional "repositoryUrl" property. Since I cannot check it with your build environment, I've created a small demo to show that "project.hasProperty" properly detects the presence of the gradle property "repositoryUrl". I edited "getRepositoryUrl" to throw an exception if "repositoryUrl" is set: ```` def getRepositoryUrl() { if (project.hasProperty('repositoryUrl')) throw new GradleException(property('repositoryUrl')) return project.hasProperty('repositoryUrl') ? property('repositoryUrl') : 'https://oss.sonatype.org/service/local/staging/deploy/maven2/' } ```` Then I ran gradle with "repositoryUrl" set like this (passing the property): ```` ./gradlew -PrepositoryUrl=blah assembleDebug ```` As expected, it detected that "repositoryUrl" was set and threw an exception: ```` * What went wrong: A problem occurred configuring project ':ContextMenuAndroid'. > Could not resolve all dependencies for configuration ':ContextMenuAndroid:_debugPublish'. > A problem occurred configuring project ':ReactAndroid'. > blah ```` The same issue has been reported before - #14811, #14810 Minor changes in the Android build script Closes https://github.com/facebook/react-native/pull/18075 Differential Revision: D7077788 Pulled By: hramos fbshipit-source-id: ecfbab29d0632e7eecb3c6a247df39bc7616653e
2018-02-24 03:00:08 +00:00
return project.hasProperty('repositoryUrl') ? property('repositoryUrl') : 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
}
def getRepositoryUsername() {
Update ReactAndroid build script to support gradle 2.3.0 Summary: We updated to Gradle 2.3.0 and our app's build failed. Our app doesn't provide "repositoryUrl" which is intended to be an optional gradle property. However, Gradle 2.3.0 blows up on findProperty('repositoryUrl') when "repositoryUrl" isn't provided: ```` * What went wrong: A problem occurred configuring project ':ContextMenuAndroid'. > Could not resolve all dependencies for configuration ':ContextMenuAndroid:_debugPublish'. > A problem occurred configuring project ':ReactAndroid'. > Could not get unknown property 'repositoryUrl' for project ':ReactAndroid' of type org.gradle.api.Project. ```` To fix this, we now use "project.hasProperty('repositoryUrl')" to safely detect the presence of the optional "repositoryUrl" property. Since I cannot check it with your build environment, I've created a small demo to show that "project.hasProperty" properly detects the presence of the gradle property "repositoryUrl". I edited "getRepositoryUrl" to throw an exception if "repositoryUrl" is set: ```` def getRepositoryUrl() { if (project.hasProperty('repositoryUrl')) throw new GradleException(property('repositoryUrl')) return project.hasProperty('repositoryUrl') ? property('repositoryUrl') : 'https://oss.sonatype.org/service/local/staging/deploy/maven2/' } ```` Then I ran gradle with "repositoryUrl" set like this (passing the property): ```` ./gradlew -PrepositoryUrl=blah assembleDebug ```` As expected, it detected that "repositoryUrl" was set and threw an exception: ```` * What went wrong: A problem occurred configuring project ':ContextMenuAndroid'. > Could not resolve all dependencies for configuration ':ContextMenuAndroid:_debugPublish'. > A problem occurred configuring project ':ReactAndroid'. > blah ```` The same issue has been reported before - #14811, #14810 Minor changes in the Android build script Closes https://github.com/facebook/react-native/pull/18075 Differential Revision: D7077788 Pulled By: hramos fbshipit-source-id: ecfbab29d0632e7eecb3c6a247df39bc7616653e
2018-02-24 03:00:08 +00:00
return project.hasProperty('repositoryUsername') ? property('repositoryUsername') : ''
}
def getRepositoryPassword() {
Update ReactAndroid build script to support gradle 2.3.0 Summary: We updated to Gradle 2.3.0 and our app's build failed. Our app doesn't provide "repositoryUrl" which is intended to be an optional gradle property. However, Gradle 2.3.0 blows up on findProperty('repositoryUrl') when "repositoryUrl" isn't provided: ```` * What went wrong: A problem occurred configuring project ':ContextMenuAndroid'. > Could not resolve all dependencies for configuration ':ContextMenuAndroid:_debugPublish'. > A problem occurred configuring project ':ReactAndroid'. > Could not get unknown property 'repositoryUrl' for project ':ReactAndroid' of type org.gradle.api.Project. ```` To fix this, we now use "project.hasProperty('repositoryUrl')" to safely detect the presence of the optional "repositoryUrl" property. Since I cannot check it with your build environment, I've created a small demo to show that "project.hasProperty" properly detects the presence of the gradle property "repositoryUrl". I edited "getRepositoryUrl" to throw an exception if "repositoryUrl" is set: ```` def getRepositoryUrl() { if (project.hasProperty('repositoryUrl')) throw new GradleException(property('repositoryUrl')) return project.hasProperty('repositoryUrl') ? property('repositoryUrl') : 'https://oss.sonatype.org/service/local/staging/deploy/maven2/' } ```` Then I ran gradle with "repositoryUrl" set like this (passing the property): ```` ./gradlew -PrepositoryUrl=blah assembleDebug ```` As expected, it detected that "repositoryUrl" was set and threw an exception: ```` * What went wrong: A problem occurred configuring project ':ContextMenuAndroid'. > Could not resolve all dependencies for configuration ':ContextMenuAndroid:_debugPublish'. > A problem occurred configuring project ':ReactAndroid'. > blah ```` The same issue has been reported before - #14811, #14810 Minor changes in the Android build script Closes https://github.com/facebook/react-native/pull/18075 Differential Revision: D7077788 Pulled By: hramos fbshipit-source-id: ecfbab29d0632e7eecb3c6a247df39bc7616653e
2018-02-24 03:00:08 +00:00
return project.hasProperty('repositoryPassword') ? property('repositoryPassword') : ''
}
def configureReactNativePom(def pom) {
pom.project {
name POM_NAME
artifactId POM_ARTIFACT_ID
packaging POM_PACKAGING
description 'A framework for building native apps with React'
url 'https://github.com/facebook/react-native'
scm {
url 'https://github.com/facebook/react-native.git'
connection 'scm:git:https://github.com/facebook/react-native.git'
developerConnection 'scm:git:git@github.com:facebook/react-native.git'
}
licenses {
license {
name 'MIT License'
url 'https://github.com/facebook/react-native/blob/master/LICENSE'
distribution 'repo'
}
}
developers {
developer {
id 'facebook'
name 'Facebook'
}
}
}
}
if (JavaVersion.current().isJava8Compatible()) {
allprojects {
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
}
}
}
afterEvaluate { project ->
task androidJavadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += files(android.bootClasspath)
classpath += files(project.getConfigurations().getByName('compile').asList())
include '**/*.java'
exclude '**/ReactBuildConfig.java'
}
task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
classifier = 'javadoc'
from androidJavadoc.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
include '**/*.java'
}
android.libraryVariants.all { variant ->
def name = variant.name.capitalize()
task "jar${name}"(type: Jar, dependsOn: variant.javaCompile) {
from variant.javaCompile.destinationDir
}
}
artifacts {
archives androidSourcesJar
archives androidJavadocJar
}
version = VERSION_NAME
group = GROUP
signing {
required { isReleaseBuild() && gradle.taskGraph.hasTask('uploadArchives') }
sign configurations.archives
}
uploadArchives {
configuration = configurations.archives
repositories.mavenDeployer {
beforeDeployment {
MavenDeployment deployment -> signing.signPom(deployment)
}
repository(url: getRepositoryUrl()) {
authentication(
userName: getRepositoryUsername(),
password: getRepositoryPassword())
}
configureReactNativePom pom
}
}
task installArchives(type: Upload) {
configuration = configurations.archives
repositories.mavenDeployer {
// Deploy to react-native/android, ready to publish to npm
repository url: "file://${projectDir}/../android"
configureReactNativePom pom
}
}
}