I have a project that is laid out like the following:
abc/
abc-core/
abc-core-actions/
abc-core-actions-a/
src/
abc-core-actions-b/
src/
abc-core-package/
src/
abc-framework/
abc-framework-core/
lib/
abc-framework-dependencies/
lib/
abc-utility/
src/
And within the lib
folders in the abc-framework
project are a bunch of jars that represent the core framework and the dependencies required for the framework to function.
What I want to accomplish is anything under abc-core
and abc-utility
to have available to them the lib
jars.
I found that doing something like this:
project(':abc-core:abc-core-actions') {
dependencies {
compile fileTree(dir: '../../abc-framework/abc-framework-core/lib', includes: ['*.jar'])
compile fileTree(dir: '../../abc-framework/abc-framework-dependencies/lib', includes: ['*.jar'])
}
}
Did work but this means for each section (abc-core:abc-core-actions-a, abc-utility, and etc.) I have to include a section like above and its also relative.
Ideally I would like to define that all subprojects have a fileTree dependency to those folders but the issue is the path changes depending on the subproject.
So what would be the best way to have the compile fileTree
reference the abc
project's absolute path?
You can use the built-in projectDir
property of any project to build an absolute path relative to one of your projects, assuming that all your projects participate in the same multi-project build.
So if you have a build.gradle
file at the top-level abc
directory, that would probably look something like this (based on your comment above):
//"project" here equates to the root project, i.e. "abc"
def frameworkCore = "${project.projectDir}/abc-framework/abc-framework-core/lib"
def frameworkDeps = "${project.projectDir}/abc-framework/abc-framework-dependencies/lib"
subprojects {
dependencies {
compile fileTree(dir: frameworkCore, includes: ['*.jar'])
compile fileTree(dir: frameworkDeps, includes: ['*.jar'])
}
}