我也遇到过类似的关于build.gradle的问题,我已经浏览了Gradle Kotlin Primer,但我不知道如何将.jar文件添加到build.gradle.kt文件中。我尽量避免使用mavenLocal()
发布于 2019-01-16 22:04:11
如果您正在寻找等效于
implementation fileTree(dir: 'libs', include: ['*.jar'])
这将是:
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
发布于 2019-06-12 15:57:39
对于带有build.gradle.kts
的Gradle5.4.1中的Kotlin dsl
使用
implementation(files("/commonjar/3rdparty/gson-2.8.5.jar"))
我建议一次添加单个文件,因为这样更容易跟踪依赖项。
完整的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")
}
发布于 2020-07-16 03:51:50
另一个答案是建议使用映射键和值,就像我们通常在Groovy中所做的那样。与使用动态方法不同,更常用且类型安全等效方法是使用闭包来过滤要包括在文件树中的文件:
api(fileTree("src/main/libs") { include("*.jar") })
https://stackoverflow.com/questions/54166069
复制相似问题