【发布时间】:2016-12-14 02:07:21
【问题描述】:
我对 intellij 和 spock 还是很陌生。
我正在使用 gradle 将 spock 测试添加到我的 Spring Boot 项目中。这是我的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'
}
}
所以我添加了一个 spock 测试:
package com.heavyweightsoftware.theta.server.controller
/**
*
*/
class ThetaControllerTest extends spock.lang.Specification {
def "Theta"() {
}
}
但我无法在我的 intellij 环境中运行测试,因为它显示“无法解析符号 'spock'”
构建直接运行良好。
【问题讨论】:
-
添加依赖项对我来说完美无缺。您是否已经尝试过 gradle 工具窗口中的“刷新所有 gradle 项目”按钮?
-
如果您没有看到 Gradle 工具窗口,请关闭并重新打开项目。当你打开它时,使用 build.gradle 文件让 IntelliJ 知道它是一个 Gradle 项目(它会询问你是否要重新导入;说“是”)。
-
@Morfic "刷新所有 radle 项目" 成功了。谢谢,我在网上的任何地方都找不到这个。你会发帖作为答案让我接受吗?
-
没问题。大多数情况下,IJ 会同步更改,但我在使用 maven 时遇到过这种情况,这通常是它再次工作的原因。只有几次我不得不强制缓存失效,因为其他任何事情都失败了
标签: intellij-idea gradle spock