[英]import failed using gradle dependency on windows 10 using IntelliJ
我正在關注 spring 引導文檔https://spring.io/guides/gs/spring-boot/但是在我做了與添加單元測試步驟相同的操作之后,即使我有相同的 Z8ED1A771BC236C28Z7 文件,項目將不會構建 932D因為導入失敗。
gs-spring-boot\complete\src\main\java\com\example\springboot\HelloControllerTest.java:3: error: package org.hamcrest does not exist
import static org.hamcrest.Matchers.equalTo;
^
error: package org.assertj.core.api does not exist
import static org.assertj.core.api.Assertions.*;
我的 gradle 文件內容
plugins {
id 'org.springframework.boot' version '2.2.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
https://github.com/spring-guides/gs-spring-boot/archive/master.zip中給出了相同的整個項目設置
這里出了什么問題? 我有 java SDK 設置,我能夠在此步驟之前運行 http 服務器。 我在 windows 10 上使用 IntelliJ 及其內置的 gradle。
不確定這是否仍然是一個有用的答案,但我也遇到了這個問題。
問題似乎是您的代碼位於“主”目錄而不是“測試”目錄中。 將測試文件移動到測試目錄為我解決了這個問題。
你錯過了Hamcrest :
// https://mvnrepository.com/artifact/org.hamcrest/hamcrest
testImplementation "org.hamcrest:hamcrest:2.2"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.