Setting jvmTarget to 11 breaks DSL

I’m migrating a project from Java 8 to Java 11 and when setting the jvmTarget to 11 in the kotlin plugin, my DSL does not work anymore, the project is here:

https://github.com/lburgazzoli/camel-kotlin-runner

When I change the property kotlin.jvm.target from 1.8 to 11, then the tests fails like none of the methods of my dsl are invoked anymore.

Note that the DSL is consumed by a kotlin script

You should provide the actual error. Otherwise, it is hard to understand what exactly is broken.

I don’t actually have a real error but a failure in a unit test, so I define a kotlin script like:

@KotlinScript(
    fileExtension = "kts", 
    compilationConfiguration = KotlinCompilationConfiguration::class)
abstract class IntegrationConfiguration(
    private val builder : EndpointRouteBuilder) 
    : BuilderSupport(builder.context), Support, EndpointBuilderFactory {

    fun rest(): RestDefinition {
        return builder.rest()
    }

    fun camel(block: CamelConfiguration.() -> Unit) {
        CamelConfiguration(context).block()
    }
}

then I have a test that validates the camel block and by setting the jvmTarget to 1.8, all of them succeed but when switching to Java 11 as jvmTarget, they start to fail.

adding some log or trying to debug them shows that the camel method is not invoked at all when jvmTarget is set to 11

You still didn’t tell us what breaks.

What failure in a unit test? What’s the output? What’s the difference between expected and actual values. etc.

The tests defines this script:

camel {
        components {
            component<org.apache.camel.component.seda.SedaComponent>("seda") {
                queueSize = 1234
                concurrentConsumers = 12
            }            
            component<org.apache.camel.component.seda.SedaComponent>("mySeda") {
                queueSize = 4321
                concurrentConsumers = 21
        }
    }
}

And checks that the components named “seda” and “mySeda” have the right values, but when switching to java 11 as jvmTarget it fails with:

[ERROR]   KotlinRouteLoaderTest.load routes with components configuration:51 
Expecting
    <org.apache.camel.component.seda.SedaComponent@1af38873>
to have a property or a field named <"queueSize"> with value
   <1234>
but value was:
   <1000>

Note that 1000 is the default value.

So there’s no “technical error” like i.e. an incompatible class or method but just a unit test failing so the script engine seems to fails silently to interpret the DSL.

That is interesting, and the approach (script configuration) is interesting.

But I am not able to reproduce the problem, works with 1.8, 11, and 13.

This is on linux with openjdk, did you different version of the jdk?

Ok, I’am able to reproduce the problem. Looks to me like the script is not being evaluated at all, but I have no idea why either.

I do have other tests in another project and it looks like only the “blocks” like

fun camel(block: CamelConfiguration.() -> Unit) 

Are not evaluated, methods with simple types, such as

fun from(uri: String): RouteDefinition

Are instead ok

Please process ‘eval’ results in KotlinRouteLoader:52

They will point to

2 = {ScriptDiagnostic@11868} "ERROR Cannot inline bytecode built with JVM target 9 into bytecode that is being built with JVM target 1.8. Please specify proper '-jvm-target' option (script.kts:3:9)"
3 = {ScriptDiagnostic@11869} "ERROR Cannot inline bytecode built with JVM target 9 into bytecode that is being built with JVM target 1.8. Please specify proper '-jvm-target' option (script.kts:7:9)"

Script targets should be also increased

2 Likes

@mbogdanov do you have any example about how to do it ?

nevermind, found it:

KotlinCompilationConfiguration : ScriptCompilationConfiguration {
    jvm {
        compilerOptions.append("-jvm-target")
        compilerOptions.append("11")
    }
}