[英]Why can't my project locate org.springframework.test or org.springframework.boot.test?
Problem: 问题:
Error:(15, 10) java: cannot find symbol
symbol: class SpringRunner
Error:(16, 2) java: cannot find symbol
symbol: class SpringBootTest
Error:(12, 47) java: package org.springframework.test.context.junit4 does not exist
Error:(10, 47) java: package org.springframework.test.context.junit4 does not exist
/home/ian/Development/JavaEE/RestCalculator/src/main/java/com/testApp/calculator/ApplicationTest.java
Error:(11, 45) java: package org.springframework.boot.test.context does not exist
Background 背景
I am trying to write a Unit test for a simple spring application. 我正在尝试为简单的Spring应用程序编写单元测试。 The application is built using Gradle.
该应用程序是使用Gradle构建的。 The following code is my build.gradle.
以下代码是我的build.gradle。
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'calculator'
version = '0.1.0'
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.10.RELEASE")
}
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("org.springframework.boot:spring-boot-starter-test")
compile("org.springframework.kafka:spring-kafka:1.3.2.RELEASE")
testCompile('junit:junit:4.12')
compile('junit:junit:4.12')
}
Attached is an image showing showing all the libraries associated with this project, which I believe includes the necessary test libraries. 随附的图片显示了与此项目相关的所有库,我相信其中包括必要的测试库。
Question 题
Why can't my project locate org.springframework.test or org.springframework.boot.test? 为什么我的项目找不到org.springframework.test或org.springframework.boot.test?
Attempts at solution 尝试解决
I have run gradle clean, followed by a build 我已经将gradle清理干净,然后进行构建
I have updated the maven central repository 我已经更新了Maven中央存储库
I tried to force the version of org.springframework:spring-* to a higher version (5.0.3.Release) 我试图将org.springframework:spring- *的版本强制为更高的版本(5.0.3.Release)
I tried using gradle-plugin:1.5.9.RELEASE 我尝试使用gradle-plugin:1.5.9.RELEASE
I figure I must be missing something in my build.gradle, but I am at my wits end as to what it is. 我认为我肯定在build.gradle中丢失了一些内容,但是我对它的内容一无所知。 Any help is appreciated.
任何帮助表示赞赏。 Thanks.
谢谢。
我已经复制了您的gradle配置,并且一切似乎都按预期进行,为避免有关启动新项目的任何问题,您可以从spring指南中下载此示例 ,然后根据需要自定义依赖项
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.