2015-09-28 92 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