Background
I'm trying to get robospock (roboelectric + spock-framework) to work as a work-around for the fact that the android gradle plugin is stupid and doesn't let me apply plugin: 'groovy'
.
However, robospock doesn't seem to work... I'm trying to override org.robospock.RobospockAction.metaClass.execute
, but everything I've tried so far has either worked on an android-library project or an android project but not vice versa.
I have tried
When testing an android-library
project, both of these worked: (full source: http://pastebin.com/pbxr4vUJ)
org.robospock.RobospockAction.metaClass.execute = { Project project ->
// Project under test
def put = project.project( project.ext.robospock )
// collect and extract compiled classes in library project
def subProjects = getSubprojects( put ).unique()
def allProjects = subProjects + put
// separate android & normal projects from each other.
def androidProjects = allProjects.findAll { isAndroid( it ) }
def normalProjects = allProjects.findAll { !isAndroid( it ) }
// collect and forward all maven dependencies
def mavenDependencies = collectMavenDependencies( allProjects ).unique()
mavenDependencies.each { dep ->
project.dependencies {
compile group: dep.group, name: dep.name, version: dep.version
}
}
// add normal projects to dependencies.
normalProjects.each { proj ->
project.dependencies { compile proj }
}
// add android projects to dependencies, in an odd way.
def main = project.sourceSets.main
def ssJava = main.java.srcDirs
def ssRes = main.resources.srcDirs
androidProjects.each { proj ->
// Find generated dir.
def variants = proj.plugins.hasPlugin( 'android-library' )
? proj.android.libraryVariants
: proj.android.applicationVariants
def genDir = variants.find { it.name == 'debug' }.dirName
// Add resource sets.
def androidMain = proj.android.sourceSets.main
ssRes.addAll( androidMain.res.srcDirs )
// Add source sets.
ssJava.addAll( androidMain.java.srcDirs )
def sourceDir = proj.buildDir.path + "/generated/source/"
["r/", "buildConfig/"].each {
ssJava.addAll( sourceDir + it + genDir )
}
}
// ...
}
or:
org.robospock.RobospockAction.metaClass.execute = { Project project ->
// Project under test
def put = project.project( project.ext.robospock )
project.dependencies { compile ':' + put.name + ':debugVersion' }
// ...
}
When I try to use the first version for a normal android
project, the build fails with: http://pastebin.com/n3AZRMg0
This claims that for example: package android.support.v4.app does not exist
- while it also states that com.android.support:support-v4:20.0.0
is a dependency (everything works when i do gradle assembleDebug).
The second version complains about not finding the project suffixed with :debugVersion
in various ways - is :debugVersion
an android-library only thingy?
When change it to project.dependencies { compile put }
it works, but does a release build as well, which is a big no-no due to signing-configs, and long build times.
TL;DR / Question
1) How do I get gradle to only use an (android project as a) dependency with debug version only - or how do I force it to at least skip doing the whole release part?
2) Why are the mysterious error outputs coming in the first version?
3) Any other ways I can solve my problem of getting robospock or spock based testing for android to work?