2016-01-20 103 views
0

我在試圖構建我的項目時遇到了NullPointerException。我目前聲明我的依賴關係properties在頂層,則在子模塊(如下所示)參考:Gradle NPE在構建?

錯誤:

A problem occurred evaluating project ':myProject'. 
> java.lang.NullPointerException (no error message) 

Caused by: java.lang.NullPointerException 
     at org.gradle.util.GUtil.flatten(GUtil.java:69) 
     at org.gradle.util.GUtil.flatten(GUtil.java:66) 
     at org.gradle.util.GUtil.collectionize(GUtil.java:93) 
     at org.gradle.util.GUtil$collectionize.call(Unknown Source) 
     at org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.methodMissing(DefaultDependencyHandler.groovy: 
     at org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.invokeMethod(DefaultDependencyHandler.groovy) 

頂層聲明:

ext.libraries = [ 

    junit: 'junit:junit:4.12', 
    mockito: 'org.mockito:mockito-all:1.9.5' 

] 

參考子模塊中的屬性:

testCompile([ 
    libraries.junit, 
    libraries.mockito 

]) 

我收到子模塊中testCompile([行的錯誤。什麼可能導致這個?

+0

可能重複[什麼是空指針異常,以及如何解決它?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how -do-i-fix-it) –

回答

1

下面的腳本gradle這個2.8正常工作:

apply plugin: 'java' 

ext.libraries = [ 

    junit: 'junit:junit:4.12', 
    mockito: 'org.mockito:mockito-all:1.9.5' 

] 

repositories { 
    mavenCentral() 
} 

dependencies { 
    testCompile(
    [ 
     libraries.junit, 
     libraries.mockito 
    ] 
) 
} 

看一看這裏的demo

+0

謝謝。儘管我有一個子模塊的build.gradle中的testcompile塊? – java123999

+0

看看演示。 – Opal