Skip to content

Commit

Permalink
Update ReactAndroid build script to support gradle 2.3.0
Browse files Browse the repository at this point in the history
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 #18075

Differential Revision: D7077788

Pulled By: hramos

fbshipit-source-id: ecfbab29d0632e7eecb3c6a247df39bc7616653e
  • Loading branch information
Sasha Nikiforov authored and facebook-github-bot committed Feb 24, 2018
1 parent 1b63da7 commit d8bb990
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ReactAndroid/release.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ def isReleaseBuild() {
}

def getRepositoryUrl() {
return hasProperty('repositoryUrl') ? property('repositoryUrl') : 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
return project.hasProperty('repositoryUrl') ? property('repositoryUrl') : 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
}

def getRepositoryUsername() {
return hasProperty('repositoryUsername') ? property('repositoryUsername') : ''
return project.hasProperty('repositoryUsername') ? property('repositoryUsername') : ''
}

def getRepositoryPassword() {
return hasProperty('repositoryPassword') ? property('repositoryPassword') : ''
return project.hasProperty('repositoryPassword') ? property('repositoryPassword') : ''
}

def configureReactNativePom(def pom) {
Expand Down

1 comment on commit d8bb990

@turnrye
Copy link
Contributor

Choose a reason for hiding this comment

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

Omitting from the changelog since this was reverted in 3f8a04b

Please sign in to comment.