How to select configurations by name


(Normand Fortier) #1

I need to copy dependencies of a number of configurations based on their name: here I want to select all configurations with name that starts with “gretty”. I tried this:
task exportGrettyLibs {
doLast {
copy {
from configurations.findAll {
config -> config.getName().startsWith(“gretty”)
}
into "$buildDir/output/libGretty"
include ‘**/*.jar’
}
}
}

but it copies dependencies for all configurations in the project. Any suggestions?


(Chris Doré) #2

Your code is working for me, except that I had to change the include pattern in order for anything to be copied.

configurations {
    grettyOne
    grettyTwo
    somethingElse
}
dependencies {
    grettyOne 'junit:junit:4.+'
    grettyTwo 'javax.inject:javax.inject:1'
    somethingElse 'commons-lang:commons-lang:+'
}
task exportGrettyLibs {
    doLast {
        copy {
            from configurations.findAll {
                config -> config.getName().startsWith("gretty")
            }
            into "$buildDir/output/libGretty"
            include '*.jar'
        }
    }
}

Results:

$ tree build
build
└── output
    └── libGretty
        ├── hamcrest-core-1.3.jar
        ├── javax.inject-1.jar
        └── junit-4.12.jar

(Chris Doré) #3

Another thought, are you sure you’re not seeing jars that were copied from one of your previous runs? Your exportGrettyLibs task does not clear the output directory and the copy method does not do that for you.

The Sync task type might be of interest to you.