How can I have gradle clone a git repository (to a sub-repo of the current one) and build it as a subproject?
Currently I have the following:
settings.gradle:
include 'contrib/dependency/foolib'
build.gradle (shortened):
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'org.ajoberstar:gradle-git:0.7.0'
}
}
apply plugin: 'com.android.application'
import org.ajoberstar.grgit.*
task clone << {
File dir = new File('contrib/dependency')
if(!dir.exists()) {
def grgit = Grgit.clone(dir: dir, uri: 'https://github.com/someone/dependency.git', refToCheckout: 'dev')
}
def grgit = Grgit.open(dir)
grgit.checkout(branch: 'dev')
grgit.pull(rebase: false)
}
project.afterEvaluate {
preBuild.dependsOn clone
}
repositories {
mavenCentral()
}
dependencies {
compile project(':contrib/dependency/foolib')
}
android {
// nothing out of the ordinary here, omitting
}
The subproject has its own build.gradle
, which builds fine on its own.
I’d gradually built and tested the script, with the clone operation first (which worked well). When I first ran the script in its full final form, the sub-repo was already/still there, thanks to the previous clone operations, and the build completed smoothly.
However, when I simulated a fresh build by simply deleting contrib
, I got an error:
Cannot evaluate module contrib/dependency/foolib : Configuration with name 'default' not found.
Apparently, this is caused by references to the still-to-be-imported subproject. How can I resolve this?