我不确定我是否错过了一个配置或偶然发现了一个bug。我正在使用IntelliJ构建一个带有JPA的KotlinSping Boot 应用程序,并希望使用Kotlin noArg插件来减少实体中的样板文件。
使用下面的build.gradle.kts,我的应用程序编译正常,但IntellJ用错误Class 'User' should have [public, protected] no-arg constructor
强调了我的实体。
我可以在IntelliJ或build.gradle中设置一些东西来消 debugging 误吗?
系统规格:
- Windows 11 + WSL
- IntelliJ IDEA 2021.3.1(终极版)
- Kotlin插件213-1.6.10-release-944-IJ6461.79
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "2.6.4"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
id("org.jetbrains.kotlin.plugin.noarg") version "1.6.10"
kotlin("jvm") version "1.6.10"
kotlin("plugin.spring") version "1.6.10"
kotlin("plugin.jpa") version "1.6.10"
}
group = "XXXXXX"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_16
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
developmentOnly("org.springframework.boot:spring-boot-devtools")
runtimeOnly("com.h2database:h2")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.security:spring-security-test")
}
noArg {
annotation("javax.persistence.Entity")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "16"
}
}
4条答案
按热度按时间ttygqcqt1#
我也遇到了同样的问题,但是在我的Maven项目中。这个东西在
<executions>
块中。可能IDEA还不理解这么复杂的配置。我删除了它,保留了这个简单的配置。ymzxtsji2#
原来这是运行在基于WSL的项目上的IntelliJ中的一个错误。
我在这里跟踪错误https://youtrack.jetbrains.com/issue/KTIJ-21314/,一旦解决,我会更新答案。
9q78igpj3#
你只需要重新加载项目,对我来说,它在一个maven项目中工作。
83qze16e4#
如果您使用新版本java,javax将更改为jakarta
Java Persistence API(JPA),2019年更名为Jakarta Persistence
因此您可能需要像这样配置pom.xml文件
和插件依赖关系