How to add local .jar file dependency to build.gradle file?

前端 未结 17 2036
攒了一身酷
攒了一身酷 2020-11-21 23:23

So I have tried to add my local .jar file dependency to my build.gradle file:

apply plugin: \'java\'

sourceSets {
    main {
        java {
            srcD         


        
17条回答
  •  旧巷少年郎
    2020-11-21 23:42

    A solution for those using Kotlin DSL

    The solutions added so far are great for the OP, but can't be used with Kotlin DSL without first translating them. Here's an example of how I added a local .JAR to my build using Kotlin DSL:

    dependencies {
        compile(files("/path/to/file.jar"))
        testCompile(files("/path/to/file.jar"))
        testCompile("junit", "junit", "4.12")
    }
    

    Remember that if you're using Windows, your backslashes will have to be escaped:

    ...
    compile(files("C:\\path\\to\\file.jar"))
    ...
    

    And also remember that quotation marks have to be double quotes, not single quotes.


    Edit for 2020:

    Gradle updates have deprecated compile and testCompile in favor of implementation and testImplementation. So the above dependency block would look like this for current Gradle versions:

    dependencies {
        implementation(files("/path/to/file.jar"))
        testImplementation(files("/path/to/file.jar"))
        testImplementation("junit", "junit", "4.12")
    }
    

提交回复
热议问题