找到在此線程解決方案:https://discuss.gradle.org/t/is-it-possible-to-set-eclipses-java-library-path-from-build-gradle/6511/6
添加以下代碼到我的gradle這個build文件並重新運行gradle eclipse
解決該問題:
的build.gradle:
def getSqlLite4JavaNativeLibraryPath() {
return configurations.runtime.resolve().findResult { entry ->
String absolutPath = entry.getAbsolutePath();
if(absolutPath.contains("sqlite4java-win32-x64")){
// return the directory that contains the native library
return entry.getParent()
}
}
}
eclipse.classpath.file.whenMerged { classpath ->
//remove the all native libraries as direct dependencies
classpath.entries.removeAll {
entry -> entry.kind == 'lib' && (entry.path.endsWith('.dll')
|| entry.path.endsWith('.so')
|| entry.path.endsWith('.dylib'))
}
//but add them as native libraries
def sqlite4java = classpath.entries.findResult { entry ->
if (entry.kind == 'lib' && entry.path.contains('sqlite4java')) {
return entry
}
}
sqlite4java.setNativeLibraryLocation(getSqlLite4JavaNativeLibraryPath())
}
的生成的.classpath文件現在包含本機庫目錄的屬性。
的.classpath:
<classpathentry sourcepath="C:/Users/user1/.gradle/caches/modules-2/files-2.1/com.almworks.sqlite4java/sqlite4java/1.0.392/2efe18f7bea6fa9536802dd4ea54d948117216c6/sqlite4java-1.0.392-sources.jar" kind="lib" path="C:/Users/user1/.gradle/caches/modules-2/files-2.1/com.almworks.sqlite4java/sqlite4java/1.0.392/d6234e08ff4e1607ff5321da2579571f05ff778d/sqlite4java-1.0.392.jar" exported="true">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="C:\Users\user1\.gradle\caches\modules-2\files-2.1\com.almworks.sqlite4java\sqlite4java-win32-x64\1.0.392\d20dc00abecc7e0bde38c68eee68f2e70c26df95"/>
</attributes>
</classpathentry>
我也跑進了gradle這個單元測試未能加載sqlite4java本機庫的問題,所以我還需要以下添加到我的gradle這個測試的目標,這樣的從Gradle運行的測試將能夠加載sqlite4java本地庫。
test {
systemProperty "sqlite4java.library.path", getSqlLite4JavaNativeLibraryPath()
}