Search code examples
kotlingradlegroovyjava-native-interfacegradle-kotlin-dsl

What's equivalent of the groovy gradle JNI configuration in kotlin gradle script?


I'm having hard time converting the following groovy script to a kotlin script (build.gradle -> build.gradle.kts).

model {
    components {
        main(NativeExecutableSpec) {
            sources {
               // ...
            }
        }
    }
}

All the docs I found Build native software, Setup JNI development in Gradle project all have groovy syntax, but none of them have kotlin syntax. Tried finding on other OS projects but found nothing.

I was trying to find some of the type info to get some clue: enter image description here

And trying out the stuff in kts:

val model by tasks.getting(ModelReport::class) {
    components {
        // ...
    }
}

But seems like there's no property called components in that object. enter image description here

Basically can't figure out anything on my own now, if somebody can help it will be greatly appreciated!


Solution

  • The old native plugin that you try to use (c) usees the rule-based software model. Those plugins are (or will be) deprecated and instead the replacements like cpp-library should be used.

    The tutorial link you posted also has a link to an example of how to use the replacement plugins in Groovy DSL that you should be able to port to Kotlin DSL easily.

    Besides that, https://docs.gradle.org/current/userguide/kotlin_dsl.html states in the section "Limitations":

    The Kotlin DSL will not support the model {} block, which is part of the discontinued Gradle Software Model. However, you can apply model rules from scripts — see the model rules sample for more information.