Gradle: How to define sourceControl with sub-path as dependency?

Viewed 1054

Using the sourceControl-Tag I want to use a public repository from google as a dependency within my own project. The repository contains some example java-class which I want to include/use. But since the gradle module/project which providing the neccessary gradle-stuff is located deeper in the file structure of the repository (=> not at root) I struggle on referencing the correct URL. In my settings.gradle I add some lines like that:

 sourceControl {
      gitRepository("https://github.com/google-ar/arcore-android-sdk.git")) {
          producesModule("com.google.ar.core.examples:app")
      }
  }

The modules which Im interested in can be fined at https://github.com/google-ar/arcore-android-sdk/tree/master/samples/hello_ar_java

1 Answers

Source dependencies is a very cool feature, but is unfortunately rather poorly documented. In cases like this, we have to look at the API documentation. The API for SourceControl is here (which is the outermost block you use). Here we can see that a gitRepository can be configured through VersionControlRepository. And in this, we see that besides the producesModule method, there is also a setRootDir method with the description:

void setRootDir​(String rootDir)

Sets the relative path to the root of the build within the repository.

So, based on your repository path, try with this:

sourceControl {
    gitRepository("https://github.com/google-ar/arcore-android-sdk.git") {
        producesModule("com.google.ar.core.examples:app")
        rootDir = "samples/hello_ar_java"
    }
}
Related