所以我尝试将本地.jar文件依赖项添加到build.gradle文件中:
apply plugin: 'java' sourceSets { main { java { srcDir 'src/model' } } } dependencies { runtime files('libs/mnist-tools.jar', 'libs/gson-2.2.4.jar') runtime fileTree(dir: 'libs', include: '*.jar') }
你会看到我将.jar文件添加到了这里的referencedLibraries文件夹中:https : //github.com/WalnutiQ/wAlnut/tree/version-2.3.1/referencedLibraries
referencedLibraries
https : //github.com/WalnutiQ/wAlnut/tree/version-2.3.1/referencedLibraries
但是问题是,当我在命令行上运行命令:gradle build时,出现以下错误:
error: package com.google.gson does not exist import com.google.gson.Gson;
如果你确实需要从本地目录中获取该.jar,
在模块gradle旁边添加(不是应用gradle文件):
repositories { flatDir { dirs 'libs' } } dependencies { implementation name: 'gson-2.2.4' }
但是,作为实际Maven存储库中的标准.jar,为什么不尝试呢?
repositories { mavenCentral() } dependencies { implementation 'com.google.code.gson:gson:2.2.4' }
据文档,对本地jar依赖项使用相对路径,如下所示:
dependencies { implementation files('libs/something_local.jar') }