【发布时间】:2019-01-25 01:28:34
【问题描述】:
我已经使用 Spring Tool Suite 启动了一个 Gradle 项目。按照本教程:https://spring.io/guides/gs/gradle/ 表示我应该在我的 build.gradle 文件中添加 org.joda 依赖项,在类中导入依赖项,构建包,然后它应该可以使用了。但是,当我这样做并重新构建项目并运行它时,我得到了错误:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
LocalTime cannot be resolved to a type
LocalTime cannot be resolved to a type
at firstGradleProject.HelloWorld.main(HelloWorld.java:7)
我的依赖项似乎设置正确:
dependencies {
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile('joda-time:joda-time:2.2')
testCompile('junit:junit:4.12')
}
如何在我的 Gradle Spring 项目中导入此依赖项并使其编译?
我的整个 build.gradle 文件如下所示:
buildscript {
ext {
springBootVersion = '2.0.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
jar {
baseName = 'gs-gradle'
version = '0.1.0'
}
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile('joda-time:joda-time:2.2')
testCompile('junit:junit:4.12')
}
【问题讨论】:
-
听起来IDE由于缺少类型而显示了一些关于编译问题的错误,对吧?您是否将 Buildship 扩展安装到您的 STS 安装(这是对 Eclipse 的 Gradle 支持)?
-
您是否尝试在 IDE 之外执行 Gradle 构建,例如在命令行中(例如 git bash 或 MS Powershell),结果是什么?
标签: java spring spring-boot gradle spring-tool-suite