I want to build a java project with several dependencies in gradle,
some are jar dependencies from the maven central repository, some are
other java project dependencies, but there is also a native JNI
dependency. I’ve managed to build the native dependency with gradle as a
seperate project.
Now I want to import the compiled .so library as a depedency in my java project. I thought it would work something like this:
The project is also listed in my settings.gradle file. However, when I compile the project, I can get an error:
Could not determine the dependencies of task ':test
Configuration with name ‘default’ not found.
So something must be misconfigured. What is the right way (I hope
there is one) to compile a native project and import the .so file in the
calling project?
If you use a dependency on a project Gradle will try to resolve the default configuration which doesn’t exist in your case. What you can do is to declare an explicit dependency on a file:
dependencies {
compile files('path/to/lib.so')
}
Ideally you should have some task that produces the the native library, so you could write something like:
Sorry I should have made it clear that createLibrary is the name of the task which generates the binary. Since you are using the native plugin, the code should probably be something like:
You could determine the actual ‘nativeOfStaticLibraryBinary’ by running gradle components in the native project.
You might need to add an explicit evaluationDependsOn to ensure that the native project is fully evaluated before the project that declares the dependency.