0

I am getting a NullPointerException when trying to build my project. I currently declare my dependencies as properties in top level, then reference in sub-modules (shown below):

Error:

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)  

Top level declaration:

ext.libraries = [

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

]

Referencing property in sub-module:

testCompile([
   libraries.junit,
   libraries.mockito

])

I am getting the error at the testCompile([ line in the sub-module. What could be causing this?

Opal
  • 81,889
  • 28
  • 189
  • 210
java123999
  • 6,974
  • 36
  • 77
  • 121
  • Possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – ΦXocę 웃 Пepeúpa ツ Jan 20 '16 at 11:08

1 Answers1

1

The following script works correctly with 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
    ]
  )
}

Have a look at the demo here.

Opal
  • 81,889
  • 28
  • 189
  • 210