Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Used kotlin-spring plugin, still getting class not open error

I am getting a class cannot be final, needs to be open, despite adding the kotlin-spring plugin. The whole purpose of the plugin is to not manually add the open keyword to every class.

Please guide me on getting the Kotling-Spring plugin to work with code below.

build.gradle

buildscript {
    ext.kotlin_version = "1.1.2"

    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-noarg:$kotlin_version"
    }
}

apply plugin: "kotlin"
apply plugin: "kotlin-spring"
apply plugin: "kotlin-noarg"
apply plugin: "idea"

repositories {
    mavenCentral()
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
    compile"org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
    compile "org.springframework:spring-context:4.3.8.RELEASE"
    testCompile "org.springframework:spring-test:4.3.8.RELEASE"
    testCompile "junit:junit:4.11"
}

AppConfig.java

@Configuration
class AppConfig {

    @Bean
    fun game(): Game {
        return BaseballGame(redSox(),cubs())
    }

    @Bean
    fun redSox(): Team {
        return RedSox()
    }

    @Bean
    fun cubs(): Team {
        return Cubs()
    }
}

Error:

Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: @Configuration class 'AppConfig' may not be final. Remove the final modifier to continue.
Offending resource: AppConfig

REF: https://kotlinlang.org/docs/reference/using-gradle.html#plugin-and-versions

like image 537
Jay Avatar asked Jun 02 '17 18:06

Jay


2 Answers

Had the same problem. Enabling annotation processing in Intellij solved the issue:

enter image description here

like image 186
zennon Avatar answered Oct 17 '22 21:10

zennon


Had similar problem. Couldn't run from IDE, but gradlew.bat build bootRun worked. Solved by updating Kotlin plugin in IDEA, from 1.2.40 to 1.2.41.

like image 1
aimozg Avatar answered Oct 17 '22 21:10

aimozg