3

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?

ghik
  • 10,706
  • 1
  • 37
  • 50

3 Answers3

8

To copy only compile dependencies (that is not in the provided dependencies set) to a directory, this should work:

task copyDependencies(type:Copy) {
    from (configurations.compile - configurations.provided)
    into 'build/dependencies'
}

Hope this helps.

Sten Roger Sandvik
  • 2,526
  • 2
  • 19
  • 16
4

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.

Sten Roger Sandvik
  • 2,526
  • 2
  • 19
  • 16
0

Take a look also at providedCompile without war plugin question.

There is notion of SpringSource propdeps Gradle plugin featuring provided configuration support.

Community
  • 1
  • 1
Vadzim
  • 24,954
  • 11
  • 143
  • 151