Copy dependencies excluding some configuration

gradle

Solution

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'
}

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.

Problem

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?

Original source