Is there a way to programmatically retrieve a dependency in gradle
Asked Answered
H

1

6

The use case is baselineing an osgi bundle.

I would like to retrieve from configured repositories the specified release (or the latest release) of a specified artifact (the one currently just built) such that I can use the jar file in a baseline operation (which requires the previous version and the new version).

Is there any gradle API that can be used for this?

Hogle answered 4/12, 2014 at 23:44 Comment(0)
P
0

You can access a project's dependencies like this:

configurations.compile.allDependencies from there you can iterate the DependencySet and do what you need to do.

Note: You may need to do this in an afterEvaluate closure because dependencies are not configured until after. So something like this:

project.afterEvaluate {
    def dependencySet = configurations.compile.allDependencies
    def dependenciesSize = dependencySet.size()
    for (int i = 0; i < dependenciesSize; i++) {
        def dependency = dependencySet.getAt(i)
        if (dependency.group != null && dependency.name != null) {
            if (dependency.group.equals("com.project.group") &&
                    dependency.name.equals("my-project")) {
                // Do what you need to do with the dependency you found.
            }
        }
    }
}
Poulard answered 28/7, 2016 at 16:55 Comment(1)
Not working as for gradle v 3.1.4 (dependecies size is always 0)Blinni

© 2022 - 2024 — McMap. All rights reserved.