String Templates - How to escape them?


I’m writing a Maven Pluging with Kotlin. And it happend that maven way of handling string templates are exactly same as Kotlin one.
Therefore following code having compile error, because kotlin is trying to handle “${project.testOutputDirectory}” in the Parameter annotation.

Mojo(name = "mytest", defaultPhase = LifecyclePhase.PROCESS_SOURCES) public open class FooMojo : AbstractMojo() {

  Parameter(defaultValue = “${project.testOutputDirectory}”, property = “outputDirectory”)
  private var outputDirectory : String = “”

Is there any way to tell Kotlin to ignore this “${project.testOutputDirectory}” and leave it for maven to handle it ?

Just escape the '$' sign:


    Parameter(defaultValue = “${project.testOutputDirectory}”, property = “outputDirectory”)

I've tried this before. by using "${foo}", both kotlin and maven will treat it as a normal string(no more injection from maven).

This code works for me:


annotation class Foo(val s: String)

Foo(“${}”) // “${}” in the byte code
fun main(args: Array<String>) {
  println(“${foo}”) // prints ${foo}

I think you should check whether this “$” in the annotation works in Maven at all, even from Java

Sorry, my bad.

“${foo}”  is actually working and I managed to convert the plugin code (originally written in Java) to kotlin code.

Thanks for your help