Named configurations as dependency aliases


(Mark Petrovic) #1

I have a number of projects that have dependencies that always travel together:

compile “ch.qos.logback:logback-classic:${versions.logback}”

compile “org.slf4j:log4j-over-slf4j:${versions.slf4j}”

compile “org.slf4j:jul-to-slf4j:${versions.slf4j}”

Is it possible to use the configurations support to alias these into one logical compile-dependency which I’d call “slf4j” ? So the result would look like

dependencies {
   slf4j
   compile ...
}

I’ve read the configurations documentation but somehow the description does not suggest this is a valid or intended use. Maybe I’m missing something.

Thanks.


(Peter Niederwieser) #2

It’s not a recommended practice. Instead you can just define a map of dependency declarations in the root project and reference them as needed from other projects. For example:

libraries = [
    logging: [
        "ch.qos.logback:logback-classic:${versions.logback}",
        "org.slf4j:log4j-over-slf4j:${versions.slf4j}",
        "org.slf4j:jul-to-slf4j:${versions.slf4j}"
    ]
]
dependencies {
    compile libraries.logging
}

The important point here is that the ‘dependencies’ block accepts, among other things, a list of dependency declarations.


(Mark Petrovic) #3

Perfect. Thank you.