Skip to content

Instantly share code, notes, and snippets.

@tmiyamon
Last active January 5, 2017 15:44
Show Gist options
  • Save tmiyamon/18ff74afe336d7b7915b491bb87e5206 to your computer and use it in GitHub Desktop.
Save tmiyamon/18ff74afe336d7b7915b491bb87e5206 to your computer and use it in GitHub Desktop.
Enable groovy for unit test of android project with other jvm language in gradle
dependencies {
testCompile "org.spockframework:spock-core:1.0-groovy-2.4"
testCompile "cglib:cglib-nodep:3.1"
testCompile "org.objenesis:objenesis:2.1"
}
android.applicationVariants.all {
def variantName = it.name
def capitalizedName = "${variantName[0].toUpperCase()}${variantName[1..-1]}"
def compileUnitTestJavaWithJavac = tasks.findByName("compile${capitalizedName}UnitTestJavaWithJavac")
def compileUnitTestGroovy = tasks.create(name: "compile${capitalizedName}UnitTestGroovy", type: GroovyCompile) {
source("src/test/java", "src/test/groovy")
include('**/*.groovy')
destinationDir = compileUnitTestJavaWithJavac.destinationDir
classpath = compileUnitTestJavaWithJavac.classpath
groovyClasspath = compileUnitTestJavaWithJavac.classpath
}
compileUnitTestJavaWithJavac.dependsOn(compileUnitTestGroovy)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment