如何将本地 .jar 文件依赖项添加到 build.gradle 文件?

编程入门 行业动态 更新时间:2024-10-28 13:18:15
本文介绍了如何将本地 .jar 文件依赖项添加到 build.gradle 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以我尝试将我的本地 .jar 文件依赖项添加到我的 build.gradle 文件中:

So I have tried to add my local .jar file dependency to my build.gradle file:

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 文件夹中:github/WalnutiQ/wAlnut/tree/version-2.3.1/referencedLibraries

And you can see that I added the .jar files into the referencedLibraries folder here: github/WalnutiQ/wAlnut/tree/version-2.3.1/referencedLibraries

但问题是,当我在命令行上运行命令:gradle build时,出现以下错误:

But the problem is that when I run the command: gradle build on the command line I get the following error:

error: package com.google.gson does not exist import com.google.gson.Gson;

这是我的整个存储库:github/WalnutiQ/wAlnut/tree/version-2.3.1

推荐答案

如果您确实需要从本地目录中获取 .jar,

If you really need to take that .jar from a local directory,

在您的模块 gradle 旁边添加(不是应用程序 gradle 文件):

Add next to your module gradle (Not the app gradle file):

repositories { flatDir { dirs 'libs' } } dependencies { implementation name: 'gson-2.2.4' }

然而,作为实际 Maven 存储库中的标准 .jar,您为什么不试试这个?

However, being a standard .jar in an actual maven repository, why don't you try this?

repositories { mavenCentral() } dependencies { implementation 'com.google.code.gson:gson:2.2.4' }

更多推荐

如何将本地 .jar 文件依赖项添加到 build.gradle 文件?

本文发布于:2023-11-16 14:18:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1605046.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   如何将   gradle   jar   build

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!