Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not get unknown property 'repositoryUrl' for project

I have a project employing React-Native. I'm building the RN module from source, so my project has the ReactAndroid module as a dependency.

I was trying to upgrade the project to Android gradle build tools >=2.3.2, so I could use intant-run:

buildscript {
    repositories {
        jcenter()
        mavenLocal()
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.2'
        ...
    }
}

This change forced me to upgrade gradle itself from 3.1 to 3.5 (latest stable).

Building the project suddenly produces the following gradle error

Could not get unknown property 'repositoryUrl' for project ':ReactAndroid' of type org.gradle.api.Project.

Can anyone help?

like image 630
Vaiden Avatar asked May 14 '17 18:05

Vaiden


Video Answer


1 Answers

Well, this turned out interesting.

The reason

The error pointed to the this line at the React-Native module's release.gradle:

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

Strangely enough, the problem is that hasProperty('repositoryUrl') returns true, while property('repositoryUrl') causes the error.

On gradle 3.1, hasProperty('repositoryUrl') returns false.

Apparently in gradle 3.5, hasProperty() returns true in cases where the property is indeed missing but still has a getter. In our case the getter is

def getRepositoryUrl() {...}

This is vaguely explained here.

There is however another method of checking for properties, which ignores getters, named findProperty.

The fix

So the fix was to change the following block from release.gradle:

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

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

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

To this:

def getRepositoryUrl() {
    return findProperty('repositoryUrl') != null ? property('repositoryUrl') : 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
}

def getRepositoryUsername() {
    return findProperty('repositoryUsername') !=null ? property('repositoryUsername') : ''
}

def getRepositoryPassword() {
    return findProperty('repositoryPassword') != null ? property('repositoryPassword') : ''
}

More pains experienced while building the RN module from source here.

like image 155
Vaiden Avatar answered Sep 20 '22 08:09

Vaiden