Dynamic dependency


(m m) #1

I would like to change the type of compile dependency based on the property passed during build.

dependencies {
 createServiceDependency()
}
def createServiceDependency(){
 if ( inputProperty.equals("true") )
 {
  project.dependencies.add("compile","module:component:$version")
 }
 else
 {
  project.dependencies.add("compile","project(:component)")
 }
}

Based on the input property passed ( inputProperty ) , I want to decide whether it should be simple dependency or a compile project dependency . The if loop works. But the else fails. How can we dynamically add a compile project dependency ?

Also another question : not related to this issue - If the input property is not passed , then the build throws error . Is there any graceful way of handling the case when input is not passed and I don’t get a property not found error.


(m m) #2

Please ignore the above question.

If anybody has similar requirement ( i.e you don;t want to compile the dependent project since there is no change in the dependent project or it is already compiled ) , then you can use the --no-rebuild option.