如何将本地.jar文件依赖项添加到build.gradle.kt文件?

时间:2019-01-13 04:21:22

标签: gradle-kotlin-dsl

我遇到了有关build.gradle的类似问题,并且浏览了enter image description here,但看不到如何在build.gradle.kt文件中添加.jar文件。我试图避免使用mavenLocal()

3 个答案:

答案 0 :(得分:2)

如果您正在寻找与之等效的

ActivityA

那将是:

@Override
protected void onResume() {
    super.onResume();
    if(didLoadActivity) {
        methodA(); // here you call the Method A
    } else {
        didLoadActivity = true;
    }
}

答案 1 :(得分:0)

对于Gradle 5.4.1中带有build.gradle.kts的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")
}

答案 2 :(得分:0)

另一个答案建议像在Groovy中一样使用映射键和值。与其使用这种动态方法,不如使用一种惯用的且类型安全的等效方法,是使用闭包来过滤哪些文件包含在文件树中:

api(fileTree("src/main/libs") { include("*.jar") })