2015-09-28 93 views
1

我在Eclipse中创建了新的Gradle项目New Gradle Project in EclipseEclipse - Spock和Groovy的新Gradle项目

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

因为我不需要的文件夹src/main/resourcessrc/test/resources删除他们,我也refactor->重命名的文件夹src/main/javasrc/test/java分成src/main/groovysrc/test/groovy。留下我像这样的结构:
enter image description here

然后我转换项目一个Groovy项目执行以下rightclicking项目:
enter image description here

现在我开始编辑我的build.gradle文件,这在开始看起来如下:

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' 
     } 
    } 
} 

因为我想用Groovy的,我补充一下:

  1. apply plugin: 'groovy'在文件的开头
  2. compile 'org.codehaus.groovy:groovy-all:2.4.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.5sourceCompatibility = 1.7
连续积不会再产生上述警告。

因为我想用斯波克 -Testing,我打开build.gradle并添加以下到它dependencies {...}下:

testCompile "org.spockframework:spock-core:1.0-groovy-2.4" 

我又做了构建并再次完成成功

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

  1. Person2.groovysrc/main/groovy
  2. Person2Test.groovysrc/test/groovy

Person2Test.groovy看起来是这样的:

package org.gradle 
import spock.lang.Specification 
class Person2Test { 
} 

Person2Test.groovy显示以下错误:
Groovy:unable to resolve class spock.lang.Specification


我很困惑在这里。我添加了Spockbuild.gradle,为了使其正常工作,还需要更改哪些内容?

回答

0

其实这个问题很简单,但也很微妙:在项目

我不得不用鼠标右键单击,并做了刷新所有摇篮:

enter image description here