我有一个配置了 Gradle 6.8.3 的 Spring Boot Java 11 项目。
这是build.gradle:
plugins {
id 'org.springframework.boot' version '2.4.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'application'
id 'eclipse'
}
application {
mainClass = 'com.project.Project'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
implementation group: 'com.github.dozermapper', name: 'dozer-core', version: '6.5.0'
implementation group: 'com.github.dozermapper', name: 'dozer-spring-boot-starter', version: '6.5.0'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
jar {
archiveBaseName = 'project'
archiveVersion = '0.0.1'
}
java {
sourceCompatibility = JavaVersion.VERSION_11
}
test {
useJUnitPlatform()
}
当我尝试使用 gradle build
或 gradle bootRun
构建项目时,它第一次运行。
然后如果我第二次运行它会显示错误:
Error: Could not find or load main class com.project.Project
Caused by: java.lang.ClassNotFoundException: com.project.Project
如果我删除 .gradle
文件夹并执行任何可以工作的构建命令,如果我离开该文件夹,它会显示错误。
我尝试添加以下所有组合但没有成功:
springBoot {
mainClass = 'com.project.Project'
}
bootRun {
main = 'com.project.Project'
}
bootJar {
mainClassName = 'com.project.Project'
}
我尝试将 gradle 降级到 6.6 和 5.6.4 版本,但没有成功 这只发生在 Windows 10 上。我有另一台装有 Linux Ubuntu 20.04 的电脑,它工作得很好。