Copy all my project dependencies except one

Hi,

We are migrating our maven project to gradle. While doing that we are implementing ‘copy-dependencies’ of maven-dependency-plugin in gradle.

maven-dependency-plugin allows for excluding a some groupId or including some groupId through and tags. I’m not able to find the correct implementation of that in gradle.

I have been trying below code, but it isn’t giving desired results:

task copyDep(type: Copy) {
    into projectDir

    into("build/somedir") {
        from configurations.compile {
            exclude 'com.some.pr'
            transitive false
            include '*.jar'
        }
    }

    into("build/someotherdir") {
        from configurations.compile {
            include('com.some.pr')
            include '*.jar'
            transitive false
        }
    }
}

What am i doing wrongly?

Will something like this work?

task copyDep(type: Sync) {
    from configurations.runtimeClasspath {
        exclude group: "com.some.pr"
        transitive false
    }
    into "$buildDir/somedir"
}

Just a few notes:

  • You may want to use Sync instead of Copy to keep the output folder synchronized with the configuration (otherwise you will just copy the jars into the folder, but not actually remove any old jars that are not part of the configuration anymore.
  • The compile configuration is deprecated and you should be using one of the others (see here for what is available). I’ve used the runtimeClasspath in this example.
  • I don’t think you can’t have multiple into blocks for one copy/sync task. You will have to split them up in that case.
  • The include and exclude rules for configurations can take a group and/or a module. There are more examples of this here.
  • I’ve used $buildDir to specify the build folder instead of relying on relative folders.