使用 gradle 将 jar 添加到类路径
在gradle中,有没有办法引用外部jar。我有一些外部 jar,位于项目结构之外的另一个文件夹中。有没有办法在我的 build.gradle 文件中添加对这些 jar 的引用,以便在编译过程中拾取它们?
谢谢
编辑:
我用具有以下“子任务(?)”的 allprojects 任务修改了 mu build.gradle ,如下所示:
repositories{
flatDir name:'ExternalJars',dirs:'<path to the jars>'
dependencies{
compile: 'jarname:jarname:version'
}
}
这似乎使我的构建运行得很好。有人可以阐明当我创建存储库并指定依赖项时到底发生了什么吗? - 谢谢
In gradle, is there a way to reference external jars. I have some external jars, sitting in another folder outside the project structure. Is there a way to add a reference to these jars in my build.gradle file, so that they are picked up during the compilation process?
Thanks
Edit:
I modified mu build.gradle with an allprojects task having the following 'sub-tasks(?)' as follows:
repositories{
flatDir name:'ExternalJars',dirs:'<path to the jars>'
dependencies{
compile: 'jarname:jarname:version'
}
}
This seems to make my build run just fine. Can someone shed some light on what exactly is happenning when I create the repository and specify the dependencies? - Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本思想是,它在
flatDir
中指定的根目录中查找与[artifact]-[version].[ext]
模式匹配的 jar 文件。注意:工件组被忽略(因此您可以将它们指定为
:jarname:version
),并且所有工件都假定没有传递依赖项。顺便说一句,引用本地 jar 的另一种方法是创建本地 ivy 存储库。如果您想声明传递依赖项,则需要使用它。
The basic idea is that it looks for jar files in the root directory(s) you specified in
flatDir
that match[artifact]-[version].[ext]
pattern.Note: artifact group is ignored (so you can specify them as
:jarname:version
), and also all artifacts assumed to have no transitive dependencies.By the way, another way to reference local jars is to create a local ivy repository. You'll need to use this if you want to declare transitive dependencies.