如何将本地.jar文件依赖项添加到build.gradle文件中? [英] How to add local .jar file dependency to build.gradle file?

查看:1077
本文介绍了如何将本地.jar文件依赖项添加到build.gradle文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我试图将我的本地.jar文件依赖项添加到我的build.gradle文件中:

  apply plugin:' java'

sourceSets {
main {
java {
srcDir'src / model'
}
}
}

依赖项{
运行时文件('libs / mnist-tools.jar','libs / gson-2.2.4.jar')
运行时fileTree(dir:'libs' ,包括:'* .jar')
}

你可以看到我添加了.jar文件放到referencedLibraries文件夹中: https://github.com/WalnutiQ/wAlnut/ tree / version-2.3.1 / referencedLibraries



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

 错误:com.google.gson包不存在
import com.google.gson.Gson;

以下是我的整个回购: https://github.com/WalnutiQ/wAlnut/tree/version-2.3.1

解决方案

如果您确实需要从本地目录中获取该.jar,请添加您的模块gradle(不是应用程序gradle文件):

 存储库{
flatDir {
dirs'libs'
}
}


依赖关系{
编译名称:'gson-2.2.4'
}

然而,作为一个实际的Maven仓库中的标准.jar,你为什么不试试这个?

 存储库{
mavenCentral()
}
依赖关系{
编译'com.google.code.gson:gson:2.2.4'
}


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')
} 

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

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;

Here is my entire repo: https://github.com/WalnutiQ/wAlnut/tree/version-2.3.1

解决方案

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

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

repositories {
   flatDir {
       dirs 'libs'
   }
}


dependencies {
   compile name: 'gson-2.2.4'
}

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

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

这篇关于如何将本地.jar文件依赖项添加到build.gradle文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆