Android - Gradle无法获取用户名'用户名'在null对象上

时间:2014-11-05 10:35:15

标签: android maven gradle

我使用我公司的自有存储库,并从.m2 / settings.xml获取存储库凭据。 直到最后一次更新Android Studio和Gradle插件(AS 0.8.14,Gradle 0.13.2),我一直表现不错。由于我已更新它们,因此我收到以下“Gradle项目同步”错误:

Error;(57,0) Cannot get property 'username' on null object

问题在于:

    allprojects {
       group 'com.tempos21.android.commons'
       repositories { // repositories needed in project
            mavenCentral() // maven central repository
            maven{ // another repository. Our nexus
                credentials {
                   def credentials = getCredentials("internal")
                   username = credentials["username"]
                   password = credentials["password"]
                }
                url "https://nexus1.tempos21.com/nexus/content/repositories/releases" // url of our nexus repository
        }
    }
}

我认为“凭证”对象在下一行中为空(在更新之前它不是null)。 getCredentials方法是:

// get repository credentials from .m2/settings.xml
def getCredentials(server) {
    def entries = getMavenSettingsCredentials()
    for (entry in entries) {
        if ( entry."id".text() == server ) {
            return [username: entry.username.text(), password: entry.password.text()]
        }
    }
}

getMavenSettingsCredentials是:

// read .m2/settings.xml
def getMavenSettingsCredentials() {
    String userHome = System.getProperty( "user.home" );
    File mavenSettings = new File(userHome, ".m2/settings.xml")
    def xmlSlurper = new XmlSlurper()
    def output = xmlSlurper.parse(mavenSettings)
    return output."servers"."server"
}

是否有人知道在我的gradle文件中导致此错误的最新更新是否有任何更改?

1 个答案:

答案 0 :(得分:1)

对不起,这是我的错。我不记得我更改了我的settings.xml以进行测试,该测试没有自己的存储库凭据....所以,如果有人有类似的问题,请检查您的settings.xml文件:p