I'm currently working on a project that has a native component in Rust and a Java component. The main build system is Gradle, and I want Gradle to invoke the Rust build system (Cargo) upon build, every time, to ensure that the proper shared libraries exist for JNI to take place, and for those libraries to be recompiled as needed. After research, I came up with this:
task buildRustDebug(type:Exec){
workingDir './native'
commandLine 'cargo', 'build'
}
task buildRustRelease(type:Exec){
workingDir './native'
commandLine 'cargo', 'build', '--release'
}
task buildRust(){
dependsOn 'buildRustDebug'
dependsOn 'buildRustRelease'
}
build dependsOn 'buildRust'
This all works fine, except for the last line that establishes a dependency with the build task. This line, when present, gives the following error when I attempt to run any task:
Build file '<censored>' line: 23
A problem occurred evaluating root project '<censored>'.
> Could not get unknown property 'dependsOn' for root project '<censored>' of type org.gradle.api.Project.
It looks like somehow the build task doesn't exist until after the code in my main file runs. How can I accomplish what I want? Note that this code is in the root project of a multi-project Gradle build.