我经历了有关build.gradle的类似问题,并且浏览了Gradle Kotlin Primer,但看不到如何在build.gradle.kt文件中添加.jar文件。我正在尝试避免使用mavenLocal()
Hah*_*pro 13
对于 gradle 5.4.1 中的 Kotlin dsl build.gradle.kts
用
implementation(files("/commonjar/3rdparty/gson-2.8.5.jar"))
Run Code Online (Sandbox Code Playgroud)
我建议一次添加单个文件,因为它更容易跟踪依赖项。
完整的build.gradle.kts
看起来像这样
plugins {
// Apply the java-library plugin to add support for Java Library
`java-library`
}
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
configurations { create("externalLibs") }
dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api("org.apache.commons:commons-math3:3.6.1")
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation("com.google.guava:guava:27.0.1-jre")
implementation(files("/commonjar/3rdparty/gson-2.8.5.jar"))
// Use JUnit test framework
testImplementation("junit:junit:4.12")
}
Run Code Online (Sandbox Code Playgroud)
Nic*_*las 13
另一个答案建议像我们通常在 Groovy 中那样使用映射键和值。不使用这种动态方法,更惯用且类型安全的等效方法是使用闭包来过滤要包含在文件树中的文件:
api(fileTree("src/main/libs") { include("*.jar") })
Run Code Online (Sandbox Code Playgroud)
如果您正在寻找相当于
implementation fileTree(dir: 'libs', include: ['*.jar'])
Run Code Online (Sandbox Code Playgroud)
那将是:
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
990 次 |
最近记录: |