【问题标题】:Can't find spock inside of intellij在 intellij 中找不到 spock
【发布时间】: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


【解决方案1】:

有时,IJ 在某些更改后可能不会更新项目类路径。 Maven POM filesGradle build files 似乎都发生了这种情况。通常,这很容易通过从相应的工具窗口(@98​​7654321@、gradle)强制与Reimport all gradle/maven projects 按钮同步来解决:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-07
    • 2017-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-19
    • 2013-12-05
    • 1970-01-01
    相关资源
    最近更新 更多