我在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
,爲了使其正常工作,還需要更改哪些內容?