复制依赖关系,排除某些配置 [英] Copy dependencies excluding some configuration
问题描述
假设一个这样的项目布局:
Suppose a project layout like this:
allprojects {
apply plugin: "java"
configurations {
provided
compile.extendsFrom(provided)
}
}
project("a") {
dependencies {
compile("foo:bar:1.0")
...
provided("bar:baz:3.14")
...
}
}
project("b") {
dependencies {
compile("abc:def:1.0")
...
provided("xyz:foo:3.14")
...
}
}
dependencies {
compile(project(":a"))
compile(project(":b"))
}
现在,我需要一个任务,将根目录的所有依赖关系(可传递地)复制到某个目录,但不包括提供的
配置。我怎么能做到这一点?
Now, I need a task that will copy all the dependencies of root project (transitively) to some directory, but excluding the provided
configuration. How can I do this?
推荐答案
对此有点痴迷并试图找出如何做到这一点。我用它来处理下面的gradle文件。
Was a little obsessed with this and tried to figure out how to do it. I got it to work with the following gradle file. Note the configurations part and where I copy the dependencies.
allprojects {
apply plugin: "java"
configurations {
provided
}
sourceSets {
main {
compileClasspath += configurations.provided
}
}
repositories {
mavenCentral()
}
}
project("a") {
dependencies {
compile("jdom:jdom:1.0")
provided("javax.servlet:servlet-api:2.5")
}
}
project("b") {
dependencies {
compile("javax.jcr:jcr:2.0")
provided("commons-logging:commons-logging:1.0")
}
}
dependencies {
compile(project(":a"))
compile(project(":b"))
}
task copyDependencies(type:Copy) {
from configurations.compile
into 'build/dependencies'
}
我认为这是解决这个问题的更简单的方法,但没有弄明白。但是这个工作。唯一的问题是,您必须将所提供的配置添加到idea / eclipse classpath中,以使ide集成能够正常工作。
I think it's a simpler solution to this problem, but did not figure it out. But this one works. The only thing is that you have to add provided configuration to idea/eclipse classpath too to make the ide integration work as espected.
这篇关于复制依赖关系,排除某些配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!