【发布时间】:2020-03-07 16:14:02
【问题描述】:
下面是我的 build.gradle 文件。我正在使用 java 11 和 IntelliJ 2019.2.2。当我运行应用程序时,我得到: 线程“main”java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication 中的异常
因此,错误或问题似乎与您从 gradle 版本 2.x 升级到任何 3.4 及更高版本时遇到的错误或问题相同,但我不应该在任何最新的 IntelliJ 版本中遇到错误。我已经清理了存储库、想法缓存等。主类 (com.itreatmd.emr.Application) 只有一行 - SpringApplication.run(Application.class, args) 并引发此异常。
另外,当我从命令行构建 tar 文件然后分解 tar 文件时,我看不到我的 jar 文件打包在 tar 文件的 lib 文件夹下。我显然遗漏了一些东西,大概是一些明显的东西,但就是无法处理它。
buildscript {
ext {
springBootVersion = '2.2.1.RELEASE'
}
repositories {
jcenter()
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
}
}
plugins {
id 'org.springframework.boot' version '2.2.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
id 'application'
id 'idea'
}
mainClassName = 'com.itreatmd.emr.Application'
group = 'com.itreatmd.emr'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
targetCompatibility = 1.8
repositories {
mavenCentral()
}
jar {
baseName = 'emrServices'
version = '1.0-SNAPSHOT'
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-jersey'
compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
compile group: 'commons-codec', name: 'commons-codec', version: '1.5'
compile group: 'commons-io', name: 'commons-io', version: '2.6'
compile group: 'org.json', name: 'json', version: '20180813'
compile "org.apache.httpcomponents:httpmime:4.2.3"
compile group: 'org.yaml', name: 'snakeyaml', version: '1.8'
compile group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.3.1'
compile group: 'org.springframework', name: 'spring-webmvc', version: '3.1.1.RELEASE'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
jar {
manifest {
attributes 'Main-Class': 'com.itreatmd.emr.Application',
'Class-Path': configurations.runtime.files.collect { "lib/$it.name" }.join(' ')
}
}
【问题讨论】:
-
不,恐怕没有。该问题中讨论的问题与 2016 年的 IntelliJ 版本有关。我的症状是相同的。
标签: spring-boot gradle intellij-idea gradle-plugin