Defining ear dependencies


(Willie) #1

so i have close to 400 ear files i need to convert to gradle. Take this build from one of my simple ones

project('emp') {
    apply plugin: 'ear'
    dependencies{
        deploy project(':emp-jar')
        deploy project(':emp-war')

        earlib files('libs/com-2.9.0.jar')
        earlib group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.21'
        earlib group: 'commons-lang', name: 'commons-lang', version: '2.6'
    }
}

project('emp-jar') {

}

project('emp-war') {
    apply plugin: 'war'

    dependencies{
        compile project(':emp-jar')

        compile files('libs/was8.5/dev/was_public.jar')

        compile files('libs/com-2.9.0.jar')
        compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.21'
        compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
    }
}

Now this in itself is fine. Nice and simple. But we have a problem. You see the double entry for the war and the ear projects. While this seems trivial, trust me, any form of double entry is bad in this shop. very very bad. is there a way that i can eliminate this double entry? maybe something like

[compile,earlib] files('libs/com-2.9.0.jar')

in the war or jar project would be ok. If i could figure out a way to annotate the configuration in the war and jar, i could even write a plugin that inserts the dep into the earlib config. in your thinking, take notice that one dependency did not go into the ear.

thanks


(Stefan Oehme) #2

You could write a plugin that provides an earLib configuration for jar and war projects. You’d let compileOnly extend from earLib so jar and war projects can compile against those libs. Then the same plugin can add a listener to the deploy configration of ear projects and automatically add a dependency to the earLib configuration of any project dependencies added there.


(Willie) #3

whats the syntax to extend a configuration? i didn’t know you could do that…


(Stefan Oehme) #4

Have a look a the reference documentation for an overview of everything you can do with configurations.