2016-08-08 75 views
1

我對intellij和spock很新穎。在intellij裏面找不到spock

我正在使用gradle爲我的spring引導項目添加spock測試。這裏是我的build.gradle

buildscript { 
    ext { 
     springBootVersion = '1.4.0.RELEASE' 
    } 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 
    } 
} 

apply plugin: 'java' 
apply plugin: 'eclipse' 
apply plugin: 'spring-boot' 

jar { 
    baseName = 'theta-server' 
    version = '0.0.1-SNAPSHOT' 
} 
sourceCompatibility = 1.8 
targetCompatibility = 1.8 

repositories { 
    mavenCentral() 
} 


dependencies { 
    compile('org.springframework.boot:spring-boot-starter-actuator') 
    compile('org.springframework.boot:spring-boot-starter-data-jpa') 
    compile('org.springframework.boot:spring-boot-starter-web') 
    testCompile('org.springframework.boot:spring-boot-starter-test') 
    testCompile('org.spockframework:spock-core:1.0-groovy-2.4') 
} 


eclipse { 
    classpath { 
     containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER') 
     containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8' 
    } 
} 

所以我加了一個斯波克測試這樣的:

package com.heavyweightsoftware.theta.server.controller 

/** 
* 
*/ 
class ThetaControllerTest extends spock.lang.Specification { 
    def "Theta"() { 

    } 
} 

但因爲它說:「無法解析符號‘斯波克’」我不能運行我的IntelliJ環境中測試

構建直接運行良好。

+0

添加依賴完美地工作對我來說。你是否已經嘗試了gradle工具窗口中的「刷新所有gradle項目」按鈕? – Morfic

+0

如果您沒有看到Gradle Tool窗口,請關閉並重新打開該項目。當你打開它時,使用build.gradle文件讓IntelliJ知道它是一個Gradle項目(它會詢問你是否要重新導入;說「是」)。 –

+0

@Morfic「刷新所有的饒舌項目」訣竅。謝謝,我無法在任何地方在網上找到它。你會作爲答案張貼,所以我可以接受嗎? – Thom

回答

3

有時,IJ可能在更改後不更新項目類路徑。看起來這發生在Maven POM files以及Gradle build files。通常情況下,這是很容易通過迫使與Reimport all gradle/maven projects按鈕同步從適當的工具窗口(mavengradle)解決:

Gradle

Maven