如何使用gradle链接lib中的jar? [英] How to use gradle to link a jar in lib?
问题描述
项目如下:
项目
/ src /a.java
/src /a.java
/ lib /B.jar
/lib /B.jar
/ bin
(a .java在B.jar中使用一些类)
(a.java use some class in B.jar)
如何链接B.jar并通过gradle构建项目?
How to link B.jar and build the project by gradle?
谢谢!
推荐答案
首先创建一个名为 build.gradle <的新构建脚本/ code>在项目的根级别上。您将需要应用Java插件并将源目录设置为
src
,因为它不使用默认项目布局。我们还将您的JAR文件依赖项分配给 compile
配置。运行 gradle build
将编译您的代码,运行测试(您没有)并组装模块的工件。
First of all create a new build script named build.gradle
on the root level of your project. You will need to apply the Java plugin and set your source directory to src
as it doesn't use the default project layout. We also assign your JAR file dependency to the compile
configuration. Running gradle build
will compile your code, run tests (which you don't have) and assemble your module's artifact.
apply plugin: 'java'
sourceSets {
main {
java {
srcDirs = ['src']
}
}
}
dependencies {
compile fileTree(dir: 'lib', include: 'B.jar')
}
这篇关于如何使用gradle链接lib中的jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!