Search code examples
kotlinintellij-ideagradle-kotlin-dsl

Kotlin noArg plugin not recognised by IntelliJ


I am not sure if I've missed a config or stumbled upon a bug. I am using IntelliJ to build a Kotlin Spring Boot application with JPA and would like to use Kotlin noArg plugin to reduce boilerplate in Entities.

With the build.gradle.kts below my application compiles OK but IntellJ underlines my Entity with error Class 'User' should have [public, protected] no-arg constructor.

Is there something I can set up in IntelliJ or build.gradle to make the error disappear?

System specs:

  • Windows 11 + WSL
  • IntelliJ IDEA 2021.3.1 (Ultimate Edition)
  • Kotlin plugin 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"
    }
}

enter image description here

enter image description here


Solution

  • Turns out that it's a bug in IntelliJ running on WSL-based project.

    I'm tracking the bug here https://youtrack.jetbrains.com/issue/KTIJ-21314/ and will update the answer once resolved.