I want to determine the dependency type at runtime

(Gradle FAQ Bot) #1

In our project we have something like 50 components. Our teams have the concept of workspaces. Whether components have project dependencies between each other or establish an external dependency depends on which of them are checked out in the workspace as source projects. How can we model that with Gradle?

(Hans Dockter) #2

You could do something like this:

dependencies {
  def createDependency(componentName) {
   if (isCheckedOutInWorkSpace()) {
      return project(":$componentName")
   } else {
      return "org.mycompo:$componentName:$versionNumber"

Of course you would need some dynamic stuff in the settings.gradle that add all the source projects to the multi-project build.

(m m) #3

I tried this snippet - but it doesn’t seem to work. I presume we can have createDependency with no input . I am deciding the dependency based on properties passed in the build command line -pMyValue=test