Hi!
I got it it to work for a gradle project where I have to sub-projects:
mylib: this builds the native library using gradles cpp-library plugin
myjni: this uses
gradle-javacpp to generate the Java JNI interface to it.
myjni also has Unit Tests written in Java to see if everything works out. I can actually run thos tests nicely and working via `gradlew myjin:test` on my windows machine.
However, this has to be cross-plattform and I know trying to get the thing working on linux too. And here I'm struggling to get
`gradlew myjin:test`work. It always complains that the native libraries (jnimylib.so and mylib.so) can not be found.
The difference I figured out so far is, that under Windows (where I'm using mingw64) the natie libraries (*.dll) go into myjni.jar and not into myjni-windows-x86_64.jar, while on Linux the native libraries (*.so) go to myjni-linux-x86_64.jar. May this actually be the reason why they are found under windows and not under Linux?
So my questions are:
a) Is it intended that under window the *.dll do not show up in myjni-window-x86_64-mingw.jar or I'm doing something wring here?
b) How to get
myjni-linux-x86_64.jar on the class-path such thet the tests can be run via
`gradlew myjin:test
Thank you!
Kr
-Thomas (Natschläger)
PS: For reference here is my gradle.build file for myjni sub-project:
plugins {
id 'java-library'
id 'java-test-fixtures'
id 'org.bytedeco.gradle-javacpp-build' version "1.5.5"
}
dependencies {
// the java bindings depend on the native library
runtimeOnly project(path: ":mylib", configuration: 'sharedLibraryRelease')
// we need JavaCpp :)
api "org.bytedeco:javacpp:1.5.5"
// Implementation for test fixtures
testFixturesImplementation "org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}"
testFixturesImplementation "org.junit.jupiter:junit-jupiter-params:${junitJupiterVersion}"
testImplementation 'org.apache.commons:commons-math3:3.6.1'
testImplementation "org.bytedeco:javacpp:1.5.5"
testRuntimeOnly "org.bytedeco:javacpp:1.5.5:linux-x86_64"
}
/**
* Java CPP specific stuff follows
*/
ext {
println "javacppPlatform: " + javacppPlatform
}
// This setting are still a hack.
// One should not use such direct hardcoded references to files or directories of other submodules.
tasks.withType(org.bytedeco.gradle.javacpp.BuildTask) {
// tell JavaCpp where the include files referenced in the interface configuration class
includePath = [
"$projectDir/../mylib/src/main/include"
]
// tell JavaCpp in which folders to look for the libraries to link
linkPath = [
"$projectDir/../mylib/build/lib/main/release"
]
}
javacppBuildCommand {
// building of the native part of mylib is done in the mylib project.
// Hence, it is left empty intentionally.
}
javacppBuildParser {
// this is the java classes which define the JNI interface generation
classOrPackageNames = ['org.myjni.presets.*']
}
javacppBuildCompiler {
// is set in all examples to true
copyLibs = true
deleteJniFiles = false
}
sourcesJar {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}