Background:
First off I have a somewhat interesting Gradle build setup with multi-projects. I’ve created a set of tools that allows me to get dependencies from a subproject (if it exists locally) or if its missing it uses a maven dependency…
Essentially what I do in my settings.gradle is I search the parent directory for several project names, if the directory is found I do an “include someProject”
Then in my build.gradle file I have the following method
def flexibleDependency(projectName, notation) {
def depProject = project(":$projectName")
if (depProject.getProjectDir().exists()) {
depProject
} else {
dependencies.create(notation)
}
}
and have the following dependencies closure…
dependencies {
compile flexibleDependency('someproject', 'com.foo.test:someproject:1.0.0.+')
compile flexibleDependency('someproject2', 'com.foo.bar:someproject2:1.0.0.+')
}
This allows developers to have option to check out the ‘someproject’ locally and build as a multi-project or don’t check out the someproject and just pull the latest built artifact from our published artifacts…
This has been working very well and saves tons of times if you need to make significant changes to dependent projects without kicking off a million CI’s and waiting.
The Problem:
There is a project that needs a subprojects “archives” configuration for a war file. Gradle seems to only set the default configuration for dependent projects.
You get around this by doing:
dependencies {
myconfig project(path: ':someproject', configuration: 'archives')
}
My problem is I cannot access project(path: ‘someproject’, configuration: ‘archives’) outside of the dependencies closure.
What I want is this:
def flexibleDependency(projectName, notation) {
def depProject = project(path: ":$projectName", configuration: 'archives')
if (depProject.getProjectDir().exists()) {
depProject
} else {
dependencies.create(notation)
}
}
But I get the error:
Could not find method project() for arguments [{path=:someproject, configuration=archives}] on root project ‘myrootproject’.
I’m really stuck here because my dependencies inclusion is conditional and without a flexibleDependencies method developers will have comment out one or the other just to get gradle to not barf…
Any suggestions, hacks, or magic?