简体   繁体   English

使用 gradle 导入失败,依赖于使用 IntelliJ 的 windows 10

[英]import failed using gradle dependency on windows 10 using IntelliJ

I am following the spring boot documentation https://spring.io/guides/gs/spring-boot/ but after I did the same as in Add Unit Tests step, even though I have the same gradle file, the project will not build because the import failed.我正在关注 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.*;

My gradle file content我的 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()
}

and entire project setup same is given in https://github.com/spring-guides/gs-spring-boot/archive/master.zip https://github.com/spring-guides/gs-spring-boot/archive/master.zip中给出了相同的整个项目设置

文件夹

What went wrong here?这里出了什么问题? I have the java SDK setup and I am able to run the http server right before this step.我有 java SDK 设置,我能够在此步骤之前运行 http 服务器。 I am on windows 10 using IntelliJ and its built in gradle.我在 windows 10 上使用 IntelliJ 及其内置的 gradle。

Not sure if this is still a useful answer, but I also ran into this issue.不确定这是否仍然是一个有用的答案,但我也遇到了这个问题。

The problem seems to be that your code is in the 'main' directory instead of the 'test' directory.问题似乎是您的代码位于“主”目录而不是“测试”目录中。 Moving the test files into the test directory fixed this problem for me.将测试文件移动到测试目录为我解决了这个问题。

You're missing Hamcrest :你错过了Hamcrest

// https://mvnrepository.com/artifact/org.hamcrest/hamcrest
testImplementation "org.hamcrest:hamcrest:2.2"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM