2

Here is my set up. I have an Android project with a couple of Java (not Android) modules.

Recently I started using Spock (which is a testing framework based on JUnit and Groovy).

On the Java modules I simply use the groovy plugin like this:

apply plugin: 'groovy'

And then include these dependencies:

dependencies {
  testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
  testCompile 'org.codehaus.groovy:groovy-all:2.4.6'
  testCompile 'cglib:cglib-nodep:3.1'
  testCompile 'org.objenesis:objenesis:2.2'
}

On my main Android app I have this set up. On the root project I have this classpath dependency:

classpath 'org.codehaus.groovy:gradle-groovy-android-plugin:0.3.9'

And on the application module I apply it:

apply plugin: 'groovyx.grooid.groovy-android'

And configure as such:

androidGroovy {
  options {
    configure(groovyOptions) {
      // used so groovy can do it's magic, I think, not 100% sure
      javaAnnotationProcessing = true 
    }
  }
  skipJavaC = true // if disabled my CPU melts for some reason
}

I've also enabled Java 8 by using the Jack flag on Android:

jackOptions {
  enabled true
}

All the tests run perfect with Spock (Even the ones on the application module). However, when I try to run the app on a device or emulator I get multiple errors from Android studio. The errors happen at the task: compileDebugGroovyWithJack and it complains it can't find any of the classes from external dependencies (including support libraries):

enter image description here

Has anybody come across this problem before? It's quite a blocker :(

pablisco
  • 14,027
  • 4
  • 48
  • 70

2 Answers2

0

This "should" work assuming that the way JVM tests run is still the same as before jack was added to the toolchain. That is compileJava is still a task, since that is what the groovy Android plugin depends on.

That being said, this is not supported and may need to be hooked into the new process a different way.

Pieces
  • 2,256
  • 5
  • 25
  • 39
  • the projects that I am applying the `'groovy'` plugin are plain Java projects not Android. In fact, if I disable the `android groovy` plugin in the main application module the app runs without a problem (but then the tests are not found) – pablisco May 19 '16 at 00:05
  • You probably don't want to skip javac. When you have this enabled you telling the groovy compiler to compile everything which is probably skipping the jack and jill compiler altogether. Again this isn't supported and will most likely require customization to your gradle scripts to accomplish this. – Pieces May 19 '16 at 14:11
  • Without the skipJavaC the compilation never stops and takes over my CPU – pablisco May 19 '16 at 15:51
  • Ok I don't really know what to tell you other than this feature is not supported, and will not be on the roadmap for some time. – Pieces May 19 '16 at 16:15
0

Ok, after some further investigation I found out that there where two things at play here:

  • I had skipJavaC = true in the androidGroovy extension since otherwise the compiler would take over my cpu, however
  • this was caused by having the flag org.gradle.parallel set to true.

Once I commented out both configurations, the project compiles perfectly. Both passing check and deploying to an emulator :)

pablisco
  • 14,027
  • 4
  • 48
  • 70