Skip to content

Kotlin Controllers are not able to resolve Twirl templates #15

Open
@adrianpowell

Description

@adrianpowell

I started with a very simple Play application which has a Controller in Kotlin that references a Twirl template. The Twirl needs to be complied before the Kotlin so that the generated class is visible, but the Kotlin appears to be compiled first resulting in errors:

[info] Compiling 2 Kotlin sources
[error] /Users/apowell/dev/kotlin-play-poc/app/controllers/HomeController.kt: 6, 19: Unresolved reference: index
[error] /Users/apowell/dev/kotlin-play-poc/app/controllers/HomeController.kt: 11, 27: Unresolved reference: index
[error] Compilation failed. See log for more details
[error] (compile:kotlinCompile) Compilation failed. See log for more details

My Controller is:

package controllers

import play.mvc.Controller
import play.mvc.Result
import play.mvc.Results
import views.html.index

class HomeController : Controller() {

    fun home(): Result {
        return Results.ok(index.apply("Your new application is ready"))
    }
}

If I remove the reference to the Twirl template (eg: return Results.ok("Kotlin controller is working")) then the compilation is successful, Java controllers can reference this template and the application runs.

Is there a way to force the Twirl/scala compilation to happen first?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions