Transitive file dependencies in gradle

后端 未结 1 889
青春惊慌失措
青春惊慌失措 2021-02-14 18:16

I would like to control which of my dependencies in a multi-project Java build are transitive. My current solution is to set up an \"export\" configuration in the root project:<

相关标签:
1条回答
  • 2021-02-14 18:29

    If I understand your scenario correctly, then yes it's easy to do this. Just add an options closure to the end of the dependency declaration to prevent transitive dependencies (I've changed A,B,C .jar to X,Y,Z because I'm guessing they don't coincide with projects A and B):

    // Project A build.gradle
    dependencies {
       compile(files('X.jar', 'Y.jar')) { transitive = false }
       export files('Z.jar')
    }
    

    Which would prevent X.jar and Y.jar from being added to the classpath for project B.

    Alternatively, and I don't know how well this would work for you and don't really recommend it (just want you to know of the possibilities) you could do this in project B's build.gradle:

    configurations.compile.dependencies.find { it.name == "A.jar" }.exclude(jar: it)
    configurations.compile.dependencies.find { it.name == "B.jar" }.exclude(jar: it) 
    

    Hope that helps.

    0 讨论(0)
提交回复
热议问题