IntelliJ Idea 2017.3 cannot launch Kotlin Spring Boot App - @Configuration class may not be final

I was able to run the Spring Boot Kotlin application from IntelliJ 2017.3. After the last IntelliJ patch update, I cannot start this application from the IDE, having received this exception:

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: @Configuration class 'AccessConfig' may not be final

I can run it from the terminal, as usual: java -jar xxxx.jar

This makes no sense as I am using the required Kotlin Spring plugin in my Gradle configuration:

buildscript {
    ext {
        kotlinVersion = '1.2.21'
        springBootVersion = '2.0.0.RC1'
    }
    repositories {
        mavenCentral()
        maven { url "https://repo.spring.io/snapshot" }
        maven { url "https://repo.spring.io/milestone" }
        jcenter()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
        classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
        classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.3'
        classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.2'
        classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.5"
    }
}

apply plugin: 'kotlin'
apply plugin: 'kotlin-spring'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'maven'
...
sourceCompatibility = 1.8
compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

repositories {
    mavenLocal()
    maven { url "https://repo.spring.io/snapshot" }
    maven { url "https://repo.spring.io/milestone" }
    maven { url "http://repo.maven.apache.org/maven2" }
    maven { url 'https://jitpack.io' }
}

ext {
    springCloudVersion = 'Finchley.M5'
    mmaReleaseTrainVersion = 'Callao-SNAPSHOT'
    junitVersion = '5.0.2'
}

Any ideas?

UPDATE:

The easiest way to play, just create a Spring boot project with IntelliJ Spring Initializer, you will see the same result:

DemoApplication:

@SpringBootApplication
class DemoApplication

fun main(args: Array<String>) {
    SpringApplication.run(DemoApplication::class.java, *args)
}

Error:

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: @Configuration class 'DemoApplication' may not be final. Remove the final modifier to continue.
Offending resource: com.example.demo.DemoApplication

build.gradle:

buildscript {
    ext {
        kotlinVersion = '1.2.10'
        springBootVersion = '1.5.10.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
        classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
    }
}

apply plugin: 'kotlin'
apply plugin: 'kotlin-spring'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

repositories {
    mavenCentral()
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter-web')
    compile("org.jetbrains.kotlin:kotlin-stdlib-jre8:${kotlinVersion}")
    compile("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
    testCompile('org.springframework.boot:spring-boot-starter-test')
}
+11
source share
4 answers

, - Kotlin :

open Java final: .

, , , open :

@SpringBootApplication
open class DemoApplication

fun main(args: Array<String>) {
    SpringApplication.run(DemoApplication::class.java, *args)
}

, :

@SpringBootApplication - , @Configuration, @EnableAutoConfiguration @ComponentScan. @Configuration open.

@SpringBootApplication @EnableAutoConfiguration @ComponentScan, .

+15

If updating the plugins does not help, check if the kotlin version in gradle matches the idea of ​​the kotlin version.

0
source

If you get this error on IntelliJ, even with the kotlin-spring plugin, you can check if annotation processing is enabled in IntelliJ.

0
source

Source: https://habr.com/ru/post/1692976/


All Articles