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

前端 未结 17 2047
攒了一身酷
攒了一身酷 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:29

    The accepted answer is good, however, I would have needed various library configurations within my multi-project Gradle build to use the same 3rd-party Java library.

    Adding '$rootProject.projectDir' to the 'dir' path element within my 'allprojects' closure meant each sub-project referenced the same 'libs' directory, and not a version local to that sub-project:

    //gradle.build snippet
    allprojects {
        ...
    
        repositories {
            //All sub-projects will now refer to the same 'libs' directory
            flatDir {
                dirs "$rootProject.projectDir/libs"
            }
            mavenCentral()
        }
    
        ...
    }
    

    EDIT by Quizzie: changed "${rootProject.projectDir}" to "$rootProject.projectDir" (works in the newest Gradle version).

提交回复
热议问题