Gradle: Fail on adding systemProperty

I’m trying to add a .dll file to the “java.library.path” system property via gradle on my Spring Boot project. I’m using Gradle 2.1 on STS. This is the small piece of groove code within my build.gradle:

tasks.withType(JavaCompile) {
    systemProperty "java.library.path", file("./src/main/resources/META-INF/opencv-2.4.9/windows_bin/x64")
}

And I’m getting the following error:

Could not find method systemProperty() for arguments [java.library.path, D:\GitHub\TFG_1\GuiaTV\src\main\resources\META-INF\opencv-2.4.9\windows_bin\x64] on root project 'GuiaTV'
That path does exists, so I don't know where the problem is.

Any help? Thank you!

What happens if you remove the “file()” wrapper and just provide the path?

It does not work either.
Finally, I ended up adding these lines to my build.gradle script:

// The following makes "gradle build", "gradle test" work
test {
    jvmArgs = ['-Djava.library.path=./src/main/resources/META-INF/opencv-2.4.9/windows_bin/x64']
}

// The following makes "gradle run" work
run {
    jvmArgs = ['-Djava.library.path=./src/main/resources/META-INF/opencv-2.4.9/windows_bin/x64']
}

By the way, I’m also using “spring-boot” gradle plugin. That’s where the run task comes from. So, I can execute “gradle build”, “gradle test” and “gradle run” sucessfully. This is, that native library is correctly added. However, since I’m also using “eclipse” gradle plugin, I would like to add the native library simply by executing “gradle eclipse”. Instead, I must create the library on Eclipse manually, and add it to my project.

Do you really need to set java.library.path when compiling your java sources ?
Usually, it’s only needed for tests execution, in which case the following will work

test {
       systemProperty 'java.library.path', './src/main/resources/META-INF/opencv-2.4.9/windows_bin/x64'
}

The systemProperty method is only available on org.gradle.api.tasks.testing.Test class
(see Test (Gradle API 7.3))