Как добавить локальную зависимость.jar-файла в файл build.gradle.kt?
Я прошел через аналогичные вопросы, касающиеся build.gradle, и просмотрел учебник Gradle Kotlin, и не вижу, как добавить файл.jar в файл build.gradle.kt. Я пытаюсь избежать использования mavenLocal()
1 ответ
Если вы ищете эквивалент
implementation fileTree(dir: 'libs', include: ['*.jar'])
это было бы:
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
Для Kotlin dsl в gradle 5.4.1 с build.gradle.kts
использовать
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")
}
Другой ответ предлагает использовать ключи и значения карты, как мы обычно делаем в Groovy. Вместо использования этого динамического подхода более идиоматическим и безопасным по типу эквивалентом было бы использование закрытия для фильтрации файлов, которые нужно включить в дерево файлов:
api(fileTree("src/main/libs") { include("*.jar") })