Dependencies management


(Ken Diep) #1

Hi,

I am planning to convert a legacy ant build with ivy as its dependency manager to gradle. My aim is to get the basic java tasks first (compile, assemble, etc…) and port the tasks over afterwards.

I’ve encountered a minor issue with declaring dependencies and hope the community can provide some insight to this. The project uses a lot of ivy descriptor files to specify dependencies and does not have a jar associated with it. The idea is that this descriptor declare all the dependencies it needs and in the module that require it can simple just declare the use of this “parent” file.

I can work around this by declaring all dependencies it needs in the sub-project but this may be a nuisance if I were to update the version. I am thinking of creating something like;

deps.gradle

project.ext.externalDependencies.foobar = [
  'foobar': 'foo:bar:1.0',
  'foobaz': 'foo:baz:1.0'
]

subprojects will just delcare “externalDependencies.foobar” where needed. Also, is it possible for me to group dependencies? For example, given

compile (group: "org.apache.cxf", name: "cxf-rt-core", version: "2.5.11")
        compile (group: "org.apache.cxf", name: "cxf-api", version: "2.5.11")
        compile (group: "org.apache.cxf", name: "cxf-common-utilities", version: "2.5.11")
        compile (group: "org.apache.cxf", name: "cxf-rt-bindings-soap", version: "2.5.11")
        compile (group: "org.apache.cxf", name: "cxf-rt-databinding-jaxb", version: "2.5.11")
        compile (group: "org.apache.cxf", name: "cxf-rt-frontend-jaxws", version: "2.5.11")
        compile (group: "org.apache.cxf", name: "cxf-rt-frontend-simple", version: "2.5.11")
        compile (group: "org.apache.cxf", name: "cxf-rt-transports-http", version: "2.5.11")
        compile (group: "org.apache.cxf", name: "cxf-rt-transports-http-jetty", version: "2.5.11")
        compile (group: "org.apache.cxf", name: "cxf-rt-ws-addr", version: "2.5.11")
        compile (group: "org.apache.cxf", name: "cxf-tools-common", version: "2.5.11")

apache cxf declares the above modules, could I some how declare it as project.ext.externalDeps.apacheCxf = […] (where […] is all the modules above) and use it as externalDeps.apacheCxf in the sub-module?

Any insight or suggestions greatly appreciated.

Thanks


(Peter Niederwieser) #2

I am thinking of creating something like […]

Yes, that’s how it’s commonly done.

To group dependencies, you can use a list of dependencies (’[…]’) instead of a single dependency. Besides I recommend to use the short notation (e.g. ‘“org.apache.cxf:cxf-rt-core:2.5.11”’).