Absolute verses relative path

I am trying to parameterise my builds to enable other users easily adapt the build to their work.

I have

dependencies {
  compileOnly(fileTree("c:/Program Files/Moneydance3069/lib")

which works fine. I want to add a property to gradle.properties, i.e:

gradle.properties

moneydanceLib = "c:/Program Files/Moneydance3069/lib"

and in the build.gradle.kts I put

build.gradle.kts

dependencies {
    val moneydanceDir: String = rootProject.findProperty("moneydanceLib") as String
   compileOnly(fileTree("$moneydanceDir"))

It uses a path of C:\Users\xxxxx.gradle\daemon\8.3"c:\Program Files\Moneydance3069\lib" which of course doesnot work.

Does anyone know how to specify an absolute path? Through experiment a String literal works but a String variable with the same information doesn’t

The problem is not string literal vs string variable.
The problem is, that the quotes are part of the string in the properties file.
And due to that the path is not recognized as absolute path but appended to the working directory.

Thanks,
Taking the quotes off worked. I have also moved away from using fileTree as has been suggested to use the flatDir, i.e

gradle.properties
moneydanceLib = c:/Program Files/Moneydance3069/lib

build.gradle.kts

repositories {
    // Use Maven Central for resolving dependencies.
    mavenCentral()
    flatDir {
        dirs(rootProject.findProperty("moneydanceLib"))
    }
}
/*
*
*	Place module specific dependencies here
*/
dependencies {
    compileOnly(":moneydance")
    compileOnly(":httpclient-4.5.6")
    compileOnly(":httpcore-4.4.10")
    compileOnly(":gson-2.5")
1 Like

Yes, flatDir is practically always better than files or fileTree. :slight_smile: