I’ve been reading and playing around with this for a few days with not much success. I suspect this isn’t difficult, it’s just that I’m new to gradle and simply don’t know how to do this correctly.
I’ve got a directory structure filled with config files. Names of these files become my project names (which I’m doing successfully) and the path that these files are in mirror the path where my source files should live (which I’ve done successfully by hard-coding the paths). My issue is storing the path in a way that I can later parse in my build.gradle.
My directory structure/file names look something like this. Note that I expect to have duplicate file names in unique paths.
/confs --/region1 ----/qa ------projectName1.conf ------projectName2.conf ----/prod ------projectName1.conf ------projectName2.conf ----/misc ------projectPlaying.conf --/region2 ----/qa ------projectName2.conf ------projectName3.conf ----/prod ------projectName2.conf ------projectName3.conf
in my settings.gradle, I traverse the project directory.
rootDir.traverse(
type: FILES,
nameFilter: ~/.+.conf$/) { file ->
include file.name.substring(0, file.name.length() - “.conf”.length())}
I thought I could simply say ext.confFilePath=file.name in the settings file and then read it back in the build file with ext.confFilePath again, but everything I’ve tried has resulted in a “could not find property” error. I’ve also tried looking in my project, the parent project and the root project to no avail. I can only surmise that either I’m missing something basic, or these values are getting eaten by a plugin or something else.
Naturally, I’ve gotten this to work when I traverse the directory in the build file, but when I do this, it traverses the directory for every project and it breaks when I hit on two files with the same name.