Home > OS >  Android - Gradle - Adding relative path in build.gradle repository to local directory
Android - Gradle - Adding relative path in build.gradle repository to local directory

Time:08-03

I have an android project: sample-android I have a folder which I have added locally to my android project root.

And I was able to specify it in my build.gradle (top level project) as

allprojects {
    repositories {
        mavenCentral()
        google()
        maven {
            url "file:/Absolute/Path/To/Root/Dir/sample-project/"        
        }
    }
}

But the issue is that this works locally but in CI/CD and repo, this same hardcoded path doesn't exist. Could someone please help me figure out how to :

  1. Either provide a relative path to the folder (which is in root directory of the android project)
  2. How to fix the above so that the absolute path of where-ever it is being used (CI/CD etc), can be added here.

Thank you.

CodePudding user response:

Let me see if I got it right. You have a folder inside your project root folder that you want to point to from your root-level build.gradle, is that correct? If so, you can do it like this:

maven { url "${project.projectDir}/folder-name" }

CodePudding user response:

As the local dir sample-project is at the project root, have you tried using flatDir{} instead of maven{}

You can get gradle to get absolute path of the project build,gradle and apply that, for example:

allprojects {
    repositories {
        mavenCentral()
        google()
        flatDir {
            dirs new java.io.File(project.projectDir.getAbsolutePath(), "sample-project")
        }
    }
}

or use your option of maven{} you would need the following:

maven {
    url = uri("${project.getRootDir()}/sample-project")
}
  • Related