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.

mkobit
  • 43,979
  • 12
  • 156
  • 150
Magnus
  • 7,952
  • 2
  • 26
  • 52
  • Show your main class. Possible your class is `ApplicationKt`. – Ruslan Sep 22 '16 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. – Magnus Sep 22 '16 at 12:11
  • so which error you get? – Ruslan Sep 22 '16 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. – Magnus Sep 22 '16 at 23:12
  • Okay, then please checkout this project: https://github.com/IRus/kotlin-meetup – Ruslan Sep 23 '16 at 10:02
  • @IRus That project uses regular gradle, gradle-script-kotlin is a new project that allows gradle build files to be written in kotlin rather than groovy. – Magnus Sep 23 '16 at 12:37
  • Oh, sorry, i miss this point. – Ruslan Sep 23 '16 at 12:49

1 Answers1

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:

mkobit
  • 43,979
  • 12
  • 156
  • 150