2

I've managed to setup a java test in my project however I've fallen into two different pitfalls.

1) I make a Java module, I can run it and do some arbitrary tests but since my Viewmodels/presenters/models are all in my Android project it means I cannot get the objects. That's a pretty big problem, I suppose an alternative would be to create a module for just the Presenters or ViewModels + Models.. but that seems bad

2) I make a folder under src/test/java/... however when I'm in there and try to compile, due to the lambda expressions in my project I end up getting weird compilation errors due to retrolambda.

com.sun.tools.javac.code.Symbol$CompletionFailure: class file for java.lang.invoke.MethodType not found

How do I go about setting up my gradle to testCompile in a way where Retrolambda isn't messing things up? Below is my gradle for the project

apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'


buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "net.ltgt.gradle:gradle-apt-plugin:0.3"
    }
}

apply plugin: "net.ltgt.apt"

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "io.patrykpoborca.cleanarchitecture"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        encoding "UTF-8"
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    dependencies {
        apt 'com.google.dagger:dagger-compiler:2.0'
        testApt 'com.google.dagger:dagger-compiler:2.0'
        //needed to resolve compilation errors, thanks to tutplus.org for finding the dependency
        // http://stackoverflow.com/questions/27036933/how-to-set-up-dagger-dependency-injection-from-scratch-in-android-project
        //test compiles
        androidTestApt 'com.google.dagger:dagger-compiler:2.0'

        compile fileTree(include: ['*.jar'], dir: 'libs')
        compile 'com.android.support:appcompat-v7:22.2.0'
        compile 'com.google.dagger:dagger:2.0'
        provided 'org.glassfish:javax.annotation:10.0-b28'
        compile 'io.reactivex:rxandroid:0.25.0'
        compile 'com.jakewharton:butterknife:7.0.1'


        androidTestCompile 'com.google.dagger:dagger:2.0'
        testCompile 'com.google.dagger:dagger:2.0'
        testCompile 'junit:junit:4.12'
        androidTestCompile 'com.android.support.test:runner:0.3'
        // Set this dependency to use JUnit 4 rules
        androidTestCompile 'com.android.support.test:rules:0.3'
        androidTestCompile 'org.mockito:mockito-core:1.+'
        androidTestCompile('com.android.support.test:runner:0.3') {
            exclude group: 'com.android.support', module: 'support-annotations'
        }
        androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
        androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
    }
}

P.s. does anyone know how to set a Java module's JavaVersion? In my java module Lambda's compiled despite being told that the version of java was wrong... really weird, here's the gradle of the java module. Thanks!

apply plugin: 'java'

buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "net.ltgt.gradle:gradle-apt-plugin:0.3"
    }
}

apply plugin: "net.ltgt.apt"

dependencies {
    apt 'com.google.dagger:dagger-compiler:2.0'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    testCompile 'com.google.dagger:dagger:2.0'
    testCompile project(':app')
}
oorosco
  • 246
  • 3
  • 14

0 Answers0