I think you are confusing concepts here. The dependencies { ... } block is evaluated in the configuration phase which is before any tasks have been run. Here’s what I think you want to do
I change the build.gradle file as your suggestion, but build failed.
dependencies {
// build project1 if found locally
if(findProject(':project1')) {
println "Found project1 locally."
//add dependency test
project(':project1 '){
configurations {
generated
}
dependencies {
generated files({ tasks.getByName('uploadArchives') }) //the task defined in project1's build.gradle
}
}
//end dependecny test
compile project(":project1 ", configuration: 'generated')
}
}
I met below error:
Could not find method project() for arguments [{configuration=generated}, :project1 ] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.