How do you add local .jar file dependency to build.gradle.kt file?

南笙酒味 提交于 2020-05-29 04:17:04

问题


I have gone through similar questions regarding build.gradle and I have looked through the Gradle Kotlin Primer and I don't see how to add a .jar file to a build.gradle.kt file. I am trying to avoid using mavenLocal()


回答1:


If you are looking for the equivalent of

implementation fileTree(dir: 'libs', include: ['*.jar'])

that would be:

implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))



回答2:


For Kotlin dsl in gradle 5.4.1 with build.gradle.kts

use

implementation(files("/commonjar/3rdparty/gson-2.8.5.jar"))

I suggest add single file at once because it is easier to keep track of dependencies.

full build.gradle.kts look like this

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")
}


来源:https://stackoverflow.com/questions/54166069/how-do-you-add-local-jar-file-dependency-to-build-gradle-kt-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!