Grails 2.2.3 Can't Find Spock on Classpath

大憨熊 提交于 2019-12-11 01:30:40

问题


I just added spock to a Grails 2.2.3 project

  1. I added the following dependency to Buildonfig.groovy:

    plugins {
        test(":spock:0.7")
    }
    
  2. Then created my Specification class, "test/unit/LocationSpec.groovy:

    import grails.test.mixin.*
    
    import org.junit.*
    
    import spock.lang.*
    
    /**
     * See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage instructions
     */
    @TestFor(Location)
    class LocationSpec extends Specification {
    
        def setup() {
        }
    
        def cleanup() {
        }
    
        def "compare"() {
            when:
            def loc1 = new Location(description:descr1)
            def loc2 = new Location(description:descr2)
    
            then:
            loc1.compareTo(loc2) == descr1.compareTo(descr2)
    
            where:
            descr1  | descr2    | pidm1     | pidm2
            "foo"   | "foo"     | 1333868   | 1333868
        }
    }
    

However I am getting the following errors with the Specification import line:

Groovy:unable to resolve class spock.lang.Specification

回答1:


Derp! R.T.F.M.

From http://grails.org/plugin/spock:

Grails 2.2 uses Groovy 2.0, which requires a special Spock version. So to use the Spock plugin with Grails 2.2, modify you BuildConfig.groovy file to include the following:

grails.project.dependency.resolution = {
  repositories {
    grailsCentral()
    mavenCentral()
  }
  dependencies {
    test "org.spockframework:spock-grails-support:0.7-groovy-2.0"
  }
  plugins {
    test(":spock:0.7") { exclude "spock-grails-support" }
  }
}


来源:https://stackoverflow.com/questions/19320221/grails-2-2-3-cant-find-spock-on-classpath

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!