2

With regular gradle I would configure a main class like so:

bootRepackage {
    mainClass = 'demo.Application'
}

With gradle-script-kotlin, this does not work.
I think I need to somehow use the Project.configure inline function, but I have tried a few different things and I haven’t been able to make it work.

7
  • Show your main class. Possible your class is ApplicationKt. Commented Sep 22, 2016 at 10:41
  • I have multiple main classes, which is part of the reason I need to configure it, if you have only one main class it gets discovered anyway. No the problem isn't the class name, the above wont even compile let alone be evaluated. Commented Sep 22, 2016 at 12:11
  • so which error you get? Commented Sep 22, 2016 at 13:07
  • I have tried about 6 different ways of configuring the plugin all yielding various errors, I didnt include them in the question because I wanted to keep it concise and targeted to question at hand. Im not trying to solve an error, im trying to discover the proper way of doing it. Commented Sep 22, 2016 at 23:12
  • Okay, then please checkout this project: github.com/IRus/kotlin-meetup Commented Sep 23, 2016 at 10:02

1 Answer 1

2

Update - September 8th, 2017

In newer versions of the Kotlin support, you have a couple other more idiomatic ways to accomplish this:

tasks {
  "bootRepackage"(Repackage::class) {
    mainClass = "demo.Application"
  }
}

And also:

val bootRepackage by tasks.getting(Repackage::class) {
  mainClass = "demo.Application"
}

I'm sure the task will change in a new version of Spring Boot.


bootRepackage is a task of type org.springframework.boot.gradle.repackage.RepackageTask. With 0.4.1, there are no extension methods available to make this configuration obvious. You will have to do something like the following:

import org.springframework.boot.gradle.repackage.RepackageTask

(tasks.getByName("bootRepackage") as RepackageTask).apply {
  mainClass = "demo.Application"
}

Relevant open issues for Task configuration:

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

Comments

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.