Hello!
I like to achieve the following in my project:
I have to sub-projects (modules):
- producer: A
cpp-library
plugin based project which produces a native shared library - consumer: a
java-library
plugin based project which builds (JNI based) java bindings for it (it actually uses JavaCPP and the accompanying Gradle JavaCpp plugin - GitHub - bytedeco/gradle-javacpp: Gradle plugins to automate the build process of JavaCPP and JavaCV).
Both projects work fine in isolation when pointing the consumer in a hard-coded way to the build directories etc.
However, I’m really struggling in setting up the dependencies properly getting the producer build properly triggered when the consumer gets built. I went through a lot of documentation and some hints on stackoverflow but non of the solutions looked like I have assumed they should be.
In may naïve way of thinking I though it should be enough for the consumer to say something like
dependencies {
compile project(“:producer”)
}
In its build.gradle
file. But this does not do its job: I would have expected to get the :producer:build task to get triggered, which it does not.
Furthermore, in the consumer I would need to know the path to the shared library (because the Gradle JavaCpp needs to know it).
I really would appreciate any ideas how to approach my problem. As a reference I append my current two build.gradle
files below:
Kr
-Thomas
Producer (cpp-library):
plugins {
id 'cpp-library'
}
library {
baseName = "mylib"
source.from file('src/main/cpp')
privateHeaders.from file('src/main/cpp')
publicHeaders.from file('src/main/include')
linkage = [Linkage.SHARED]
targetMachines = [
machines.windows.x86_64
]
}
tasks.withType(CppCompile).configureEach {
macros.put("DLL_BUILD", "1")
}
Consumer:
plugins {
id 'java-library-convention'
id 'common-dependencies'
id 'org.bytedeco.gradle-javacpp-build' version "1.5.5"
}
dependencies {
project(":producer")
// also tried: project(path: ":producer", configuration: 'sharedLibrary')
platformClassifier.each { platform ->
api "org.bytedeco:javacpp:${javaCppVersion}"
}
}
ext {
javacppPlatform = "windows-x86_64"
}
tasks.withType(org.bytedeco.gradle.javacpp.BuildTask) {
includePath = ["$projectDir/../producer/src/main/include"]
linkPath = ["$projectDir/../producer/build/lib/main/mylib/shared"]
}
javacppBuildCommand {
// building of the native part is done by the producer project
// Hence, it is left empty intentionally.
}
javacppBuildParser {
// this is the java classes which define the JNI interface generation
classOrPackageNames = ['org.some.library.presets.*']
}
javacppBuildCompiler {
copyLibs = true
}