6

I try to create the very first Spring Boot application with Kotlin. So, maybe I made some obvious errors or something like that.

My gradle.build is:

buildscript {
    ext.kotlin_version = '1.0.5-2'
    ext.spring_boot_version = '1.4.2.RELEASE'
    repositories {
        jcenter()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_version"
    }
}

apply plugin: 'idea'
apply plugin: 'kotlin'
apply plugin: 'application'

jar {
    baseName = 'rest-voter'
    version = '0.1.0'
}

springBoot {
    mainClass = 'ru.hixon.Application'
}

repositories {
    jcenter()
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    compile "org.springframework.boot:spring-boot-starter-web:1.4.2.RELEASE"
    testCompile 'junit:junit'
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.13'
}

The error is:

C:\Users\Desktop\rest-voter>gradlew build

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\Desktop\rest-voter\build.gradle' line: 22

* What went wrong:
A problem occurred evaluating root project 'rest-voter'.
> Could not find method springBoot() for arguments [build_3594if1jtm90vgb7v8evp206i$_run_closure2@459003a0] on root project 'rest-voter'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 12.351 secs

My main class is:

package ru.hixon

import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication

@SpringBootApplication
open class Application {

}

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

And here is full code of my application.

1 Answer 1

5

You need to:

apply plugin: 'spring-boot'

as well :)

Importing the dependency is not enough.

Sign up to request clarification or add additional context in comments.

2 Comments

it is so strange. I created project, which contained this plugin. Then gradle said, that this plugin is deprecated, and I have to use org.springframework.boot:spring-boot-gradle-plugin. Then I removed it. Now I add this plugin, and there is no message about deprecated
For new spring boot versions you need to use apply plugin: 'org.springframework.boot' and then add the buildInfo() block below it to avoid build errors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.