java - 使用 IntelliJ 在 Windows 10 上使用 gradle 依赖项导入失败
问题描述
我正在关注 Spring Boot 文档https://spring.io/guides/gs/spring-boot/ 但是在我做了与添加单元测试步骤相同的操作之后,即使我有相同的 gradle 文件,项目也不会构建因为导入失败。
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 服务器。我在使用 IntelliJ 及其内置 gradle 的 Windows 10 上。
解决方案
不确定这是否仍然是一个有用的答案,但我也遇到了这个问题。
问题似乎是您的代码位于“主”目录而不是“测试”目录中。将测试文件移动到测试目录为我解决了这个问题。
推荐阅读
- optimization - 如何找出在发布模式下对 Rust 代码应用了哪些优化?
- mysql-8.0 - 查询在 MySQL 5.6 中有效,但在 MySQL 8.0 中无效
- flutter - 当我应该有空值时 - Flutter
- angular - CKEDITOR 重复模块
- php - 使用 withCount() 计算所有文章
- mongodb - 无法读取未定义的属性“原型”-带有 typeorm 和 mongoDB 的 nestjs
- sql - SQL 文件日期和时间格式
- python - 环境模块创建:Tensorflow
- kubernetes - Kubernetes - 在多行配置图中使用 Secret 中的值
- javascript - 关键依赖:一个依赖的请求是一个表达式 webpack svelte