繁体   English   中英

IntelliJ 无法识别 Kotlin noArg 插件

[英]Kotlin noArg plugin not recognised by IntelliJ

我不确定我是否错过了配置或偶然发现了错误。 我正在使用 IntelliJ 使用 JPA 构建 Kotlin Spring Boot 应用程序,并希望使用 Kotlin noArg 插件来减少实体中的样板。

使用下面的 build.gradle.kts 我的应用程序可以编译,但是 IntellJ 强调了我的 Entity with error Class 'User' should have [public, protected] no-arg constructor

我可以在 IntelliJ 或 build.gradle 中设置什么来使错误消失吗?

系统规格:

  • 视窗 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"
    }
}

在此处输入图像描述

在此处输入图像描述

我有同样的问题,但我的 Maven 项目。 事情在<executions>块中。 也许 IDEA 还不了解如此复杂的配置。 我删除了它并保留了这个简单的配置。

<plugin>
    <groupId>org.jetbrains.kotlin</groupId>
    <artifactId>kotlin-maven-plugin</artifactId>
    <version>${kotlin.version}</version>
    <configuration>
        <sourceDirs>
            <sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
            <sourceDir>${project.basedir}/src/main/java</sourceDir>
        </sourceDirs>
        <compilerPlugins>
            <plugin>jpa</plugin>
            <plugin>all-open</plugin>
            <plugin>spring</plugin>
        </compilerPlugins>
        <pluginOptions>
            <option>all-open:annotation=javax.persistence.Entity</option>
            <option>all-open:annotation=javax.persistence.Embeddable</option>
            <option>all-open:annotation=javax.persistence.MappedSuperclass</option>
        </pluginOptions>
        <args>
            <!-- https://docs.spring.io/spring-boot/docs/2.0.x/reference/html/boot-features-kotlin.html#boot-features-kotlin-null-safety -->
            <arg>-Xjsr305=strict</arg>
        </args>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-noarg</artifactId>
            <version>${kotlin.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-allopen</artifactId>
            <version>${kotlin.version}</version>
        </dependency>
    </dependencies>
</plugin>

原来这是在基于 WSL 的项目上运行的 IntelliJ 中的一个错误。

我在这里跟踪错误https://youtrack.jetbrains.com/issue/KTIJ-21314/并在解决后更新答案。

你只需要重新加载项目,对我来说它在一个 Maven 项目中工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM