Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright 2014 toxbee.se
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- apply from: 'config.gradle'
- evaluationDependsOn(ext.robospock)
- ext.sdkDir = project(project.ext.robospock).android.sdkDirectory
- buildscript {
- repositories {
- mavenCentral()
- }
- dependencies {
- // RoboSpock - Testing for Android.
- classpath 'org.robospock:robospock-plugin:0.4.0'
- }
- }
- repositories {
- mavenCentral()
- //Again the robospock-plugin does not add all the correct android dependencies
- maven { url "${sdkDir}/extras/android/m2repository" }
- maven { url "${sdkDir}/extras/google/m2repository" }
- }
- apply plugin: 'groovy'
- dependencies {
- compile "org.codehaus.groovy:groovy-all:$groovyVersion"
- compile "org.spockframework:spock-core:$spockVersion"
- compile "org.robospock:robospock:$roboSpockVersion"
- testCompile 'cglib:cglib-nodep:3.1'
- testCompile 'org.objenesis:objenesis:2.1'
- }
- // Disable the default test task otherwise commandline build fails because
- // gradle test task tries to run the specs as if they were standard spock tests
- test.onlyIf { false }
- /**
- * The findCompileDependencies method of the org.robospock:robospock-plugin does not work with the
- * latest gradle and android build tools.
- * Consider fixing the plugin and submitting
- */
- org.robospock.RobospockAction.metaClass.findCompileDependencies = { Project androidProject ->
- androidProject.configurations.all.find {
- it.name == 'compile'
- }.getAllDependencies()
- }
- def dumpCfgs( Project project, show = [] ) {
- println " Project:" + project.name
- def cfgs = project.configurations
- if ( !show.isEmpty() ) {
- cfgs = cfgs.findAll { show.contains( it.name ) }
- }
- cfgs.each { conf ->
- println " Configuration: ${conf.name}"
- conf.allDependencies.each { dep ->
- println " ${dep.group}:${dep.name}:${dep.version}"
- }
- }
- }
- def isAndroid( Project proj ) {
- return proj.hasProperty( 'android' )
- }
- /**
- * The findCompileDependencies execute of the org.robospock:robospock-plugin does not take into account
- * that the generated variants and placed in the 'generated' directory.
- * Consider fixing the plugin and submitting
- */
- org.robospock.RobospockAction.metaClass.execute = { Project project ->
- // Project under test
- def put = project.project( project.ext.robospock )
- if ( !isAndroid ( put ) ) {
- throw new IllegalArgumentException( put.name + ' is not an android project.' )
- }
- /*
- * Add dependencies
- */
- // 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 }
- }
- dumpCfgs( project, ['compile'] )
- // 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 )
- }
- }
- ssJava.each { println it }
- project.sourceSets.main {
- java.srcDirs = ssJava
- resources.srcDirs = ssRes
- }
- /*
- * Create the task
- */
- Task test = task robospock(
- type: Test,
- group: JavaBasePlugin.VERIFICATION_GROUP,
- name: org.robospock.RobospockAction.ROBOSPOCK_TASK_NAME,
- description: "Runs the unit tests using Robospock.",
- ) {
- workingDir = "${put.projectDir}/src/main"
- }
- project.getTasks().getByName( JavaBasePlugin.CHECK_TASK_NAME ).dependsOn( test )
- }
- //Plugin must be applied last and must use qualified name when applied from a gradle script
- apply plugin: 'robospock'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement