Kotlin DSL - Multiple versions of the same library

I have the same issue as the referenced issues below. Where I want two different versions of the same library. But the solution is in Groovy DSL, if I try them with Kotlin DSL the solution gives a compile error.

Referenced Issues

The attempt

configurations {
    SparkV2
    SparkV3
}
dependencies {
    SparkV2("org.scala-lang:scala-library:2.11.12")
    SparkV2("org.apache.spark:spark-sql_2.11:2.4.0")
    SparkV2("org.apache.spark:spark-avro_2.11:2.4.0")
    
    implementation("com.oracle.database.jdbc:ojdbc8:23.5.0.24.07")
    implementation("com.electronwill.night-config:toml:3.8.1")
}

Well, what do you expect if you copy Groovy code into Kotlin code?
That is like you copy C# code into Java code.
The probability that it is working is nearly 0.

Also next time, if you post about some error you get,
it would be helpful if you quote the error you are getting,
optimally as build --scan URL if you can.

configurations {
    SparkV2
    SparkV3
}

is not valid Kotlin code as you have observed.
In Groovy this is syntactic sugar for creating two configurations.
In Kotlin you would for example do

val SparkV2 by configurations.registering
val SparkV3 by configurations.registering

Besides that both, the Groovy version and the Kotlin version are creating configurations that are setup in a legacy way that you should not use.

Configurations should be dedicated to either be consumed by other projects, resolved in the current build, or used to declare dependencies on it, but not multiple of this.

1 Like

Yes I didn’t really expect it to work. But what else am I supposed to try? The documentations and examples I have seen are all for Groovy.

There’s no real harm in trying and sometimes the error codes do lead to something useful.

Anyhow the point of the code is to get the idea across. Which it did.

Thanks for the answer anyways.