I’m using Gradle with the java and eclipse plugins. My project includes sqlite4java, which uses a local JNI library to run.
Following this thread , I’ve been able to get “gradle test” to complete successfully. However, when I run “gradle eclipse”, the generated .classpath file does not include the Eclipse-specific annotation to include the sqlite4java JNI pointer. (The “attributes” tag and its contents in the below.)
<classpathentry exported="true" kind="lib" path="/Users/dhalperi/.gradle/caches/artifacts-14/filestore/com.almworks.sqlite4java/sqlite4java/0.282/jar/745a7e2f35fdbe6336922e0d492c979dbbfa74fb/sqlite4java-0.282.jar" sourcepath="/Users/dhalperi/.gradle/caches/artifacts-14/filestore/
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="myriad/lib/sqlite4java-282"/>
</attributes>
</classpathentry>
Is there a way to set up the build.gradle file so that the Eclipse plugin can propagate this information?
tasks.withType(Test) {
systemProperty "java.library.path", file("lib/sqlite4java-282")
}
Thanks!
1 Like
I think the only way to include those custom attributes in eclipse classpath entries is to use eclipse’s withXml hook. Take a look in the dsl reference for the eclipse.classpath.xml.withXml hook.
Hope that helps!
Interesting. The following works, but is pretty ugly. I’ve never used Groovy syntax before… Suggestions?
(inside eclipse.classpath)
file.withXml {
provider ->
provider.asNode().findAll { it.@path.contains("sqlite") }.each {
it.children().each {
it.appendNode('attribute', [name: 'org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY', value:'myriad/lib/sqlite4java-282'])
}
}
}
Thanks!
w25r
(William Lichtenberger)
September 26, 2013, 7:04pm
4
I was able to solve this problem by using the below code.
def jacob = classpath.entries.findResult { entry ->
if (entry.kind == ‘lib’ && entry.path.contains(‘jacob’)) {
return entry
}
}
File file = findFileInConfiguration(configurations.runtime, ‘jacob-1.17-M2-x64’)
jacob.setNativeLibraryLocation(file.getParent())
I feel this is better than modifying the resulting XML.
Hi @w25r ,
Where did you put this code? I can’t seem to figure out which subsection it goes in.
w25r
(William Lichtenberger)
October 15, 2013, 2:44pm
6
I can’t seem to edit my post, let’s see if I can do mark up syntax in a comment.
eclipse.classpath.file.whenMerged { classpath ->
//remove the dlls as direct dependencies
classpath.entries.removeAll { entry -> entry.kind == ‘lib’ && entry.path.contains(‘dll’) }
//but add them as native libraries
def jacob = classpath.entries.findResult { entry ->
if (entry.kind == ‘lib’ && entry.path.contains(‘jacob’)) {
return entry
}
}
File file = findFileInConfiguration(configurations.runtime, ‘jacob-1.17-M2-x64’)
jacob.setNativeLibraryLocation(file.getParent())
}