Can I pass arguments to `kotlinc` directly from co...
# gradle
p
Can I pass arguments to
kotlinc
directly from command line?
v
Only if you program that into your build script manually
p
Copy code
tasks.withType<Kotlin2JsCompile> {
    kotlinOptions {
        freeCompilerArgs += "-Xir-property-lazy-initialization"
    }
}
Well, then I have this, but I don't want to use this parameter when compiling tests. How to do that?
v
Don't do it for all tasks of that type
For example
Copy code
tasks.withType<Kotlin2JsCompile> {
    if (name != "whateverthetesttasknameis") {
        kotlinOptions {
            freeCompilerArgs += "-Xir-property-lazy-initialization"
        }
    }
}
p
if (!name.contains("test", true))
🤷🏻‍♂️ Isn't there a better way to detect test tasks?
v
It's not a test task, it is a compilation task that compiles some source files to class files. The compilation task is not aware of what it compiles semantically. So you have to use some identifying attribute. You can check the name, you can check the source file paths, you can check whatever you want. But the task per-se does not know what it compiles. (Except if this is different for Kotlin compilation tasks, but I doubt it)
You could instead just targeted enable the option for the tasks where you want it instead of doing it for all tasks of a given type
p
Can't it know something like parent task(s)? So if one of the parent is Test type task, I can do something?
v
I don't think so, at least not easily or cleanly. Also because this relation might not even have been configured yet when your configuration code is executed.
p
Ok, I'll stick with
name
🙂