I am dealing with some JNI code and I would like to run the JUnit tests with the native libraries the project just generated.
As the different projects generate different number of DLLs (I am migrating existing build), it would be nifty if Gradle would allow me to find the output directories for all LinkSharedLibrary
tasks. Unfortunately the LinkSharedLibrary
tasks are added very late in the game, when the test task has been already configured.
The best I could come up with is this, but it looks ugly:
def suffix = "${platform}${testBuildType}SharedLibrary"
def libPath = [] as Set
tasks.whenTaskAdded { t ->
if (t instanceof LinkSharedLibrary && t.name.endsWith(suffix)) {
libPath << t.linkedFile.asFile.get().parent
def lp = libPath.join(File.separator)
thisTest.systemProperties."java.library.path" = lp
if (os.isLinux()) {
thisTest.environment.LD_LIBRARY_PATH = lp
}
}
}
Is there a better way?