Checking for dependencies


(Eric Doyon) #1

In my particular use case I want to make development easier for my team.

I have an artifactory repo to store multiple projects. I am appending the git branch to the group id of the artifacts (it couple be done in the version or the name, but in this case I decided to do it in the group). When a new project is created I want to resolve my dependencies from artifactory based on the current git branch I’m in (this works fine) the problem arises when I want to default to use a different dependency if the one I’m looking for cant be found.

example: I’m currently working on a project for a new feature ABC

dependencies {
compile group: “group.name.${git_branch}”, name: “project-x”, version:“0.0.1”
}

if I have checkout an ABC branch for project-x then that dependency will work.
However if project-x doesn’t need to change then I would like it to default to a different branch, let’s say master.

I can do that if I make the configuration optional

configurations {
optional
}

sourceSets {
main {
compileClasspath = files({configurations.optional.resolvedConfiguration.lenientConfiguration.getFiles(Specs.satisfyAll())}).plus(compileClasspath)
}
}

dependencies {
optional (group: “group.name.${git_branch}”, name: “project-x”, version:“0.0.1”)
optional (group: “group.name.master”, name: “project-x”, version:“0.0.1”)
}

The problem with that, is in the case where there is a feature branch for project-x, then I will get 2 dependencies for it.

What I really need is to have my second dependency only resolve if my first doesn’t.

This is a very simplified example. My goal is just to make branching and resolving dependencies very simple for our developers without needing to branch and publish artifacts and manage where their project resolves artifacts from.