我在Eclipse中创建了新的Gradle项目。 Eclipse - Spock和Groovy的新Gradle项目
因为我不需要的文件夹src/main/resources
和src/test/resources
我删除他们,我也refactor->重命名的文件夹src/main/java
和src/test/java
分成src/main/groovy
和src/test/groovy
。留下我像这样的结构:
然后我转换项目到一个Groovy项目由执行以下rightclicking项目:
现在我开始编辑我的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的,我补充一下:
apply plugin: 'groovy'
在文件的开头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.5
到sourceCompatibility = 1.7
和连续积不会再产生上述警告。
因为我想用斯波克 -Testing,我打开build.gradle
并添加以下到它dependencies {...}
下:
testCompile "org.spockframework:spock-core:1.0-groovy-2.4"
我又做了构建并再次完成成功。
现在我要开始编码,因此我新文件添加:
Person2.groovy
到src/main/groovy
Person2Test.groovy
到src/test/groovy
Person2Test.groovy
看起来是这样的:
package org.gradle
import spock.lang.Specification
class Person2Test {
}
Person2Test.groovy
显示以下错误:
Groovy:unable to resolve class spock.lang.Specification
我很困惑在这里。我添加了Spock到build.gradle
,为了使其正常工作,还需要更改哪些内容?