簡體   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