Eclipse - Spock和Groovy的新Gradle项目

时间:2015-09-28 07:35:44

标签: eclipse groovy gradle build.gradle spock

我正在Eclipse中创建一个新的Gradle项目New Gradle Project in Eclipse

创建具有以下结构的新项目:
enter image description here

因为我不需要文件夹src/main/resourcessrc/test/resources删除他们,我还重构 - >重命名文件夹{{1 {}}和src/main/java加入src/test/javasrc/main/groovy。离开我这样的结构:
enter image description here

然后我转换项目转换为 Groovy项目,通过右键单击项目执行以下操作:
enter image description here

现在我开始编辑我的src/test/groovy文件,开头看起来如下:

build.gradle

由于我想使用 Groovy ,我添加:

  1. apply plugin: 'java' apply plugin: 'eclipse' sourceCompatibility = 1.5 version = '1.0' jar { manifest { attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version': version } } repositories { mavenCentral() } dependencies { compile group: 'commons-collections', name: 'commons-collections', version: '3.2' testCompile group: 'junit', name: 'junit', version: '4.+' } test { systemProperties 'property': 'value' } uploadArchives { repositories { flatDir { dirs 'repos' } } } 位于文件开头
  2. apply plugin: 'groovy'加入compile 'org.codehaus.groovy:groovy-all:2.4.3'
  3. 然后我点击构建,完成成功,但通知我一个警告:

    dependencies{...}

    要摆脱此警告,我会再次修改[sts] ----------------------------------------------------- [sts] Starting Gradle build for the following tasks: [sts] build [sts] ----------------------------------------------------- :compileJava UP-TO-DATE :compileGroovywarning: [options] bootstrap class path not set in conjunction with -source 1.5 1 warning :processResources UP-TO-DATE :classes :jar :assemble :compileTestJava UP-TO-DATE :compileTestGroovywarning: [options] bootstrap class path not set in conjunction with -source 1.5 1 warning :processTestResources UP-TO-DATE :testClasses :test :check :build BUILD SUCCESSFUL Total time: 2.496 secs [sts] ----------------------------------------------------- [sts] Build finished succesfully! [sts] Time taken: 0 min, 2 sec [sts] ----------------------------------------------------- ,将build.gradle更改为sourceCompatibility = 1.5连续构建不再产生上述警告。

    由于我想使用 Spock -Testing,我会打开sourceCompatibility = 1.7并在build.gradle下添加以下内容:

    dependencies {...}

    我再次执行构建,然后再次成功

    现在我想开始编码,因此我添加新文件

    1. testCompile "org.spockframework:spock-core:1.0-groovy-2.4" Person2.groovy
    2. src/main/groovyPerson2Test.groovy
    3. src/test/groovy看起来像这样:

      Person2Test.groovy

      package org.gradle import spock.lang.Specification class Person2Test { } 显示以下错误:
      Person2Test.groovy

      我在这里很困惑。我将 Spock 添加到Groovy:unable to resolve class spock.lang.Specification,还需要更改哪些才能让它正常工作?

1 个答案:

答案 0 :(得分:0)

实际上问题很简单,但也非常微妙:

我必须右键单击该项目并为Gradle执行全部刷新:

enter image description here