Hi,
I’m trying to configure a native library (google-test), for which the sources are downloaded during the build. The problem is that if the source files are not present at the time the model is configured, nothing will be built when executing the corresponding task, even if the source files are present at that time. I basically need to run a task before the model is configured, or I need to force the model to reconfigure after a certain task is executed. Otherwise I have to run the task always twice. Is this possible?
//build.gradle
plugins {
id "cpp"
id "google-test"
id "de.undercouch.download" version "1.2"
}
model {
components {
gtest(NativeLibrarySpec) {
sources.cpp(CppSourceSet) {
source.srcDir "${buildDir}/downloads/gtest"
source.include 'src/gtest-all.cc'
exportedHeaders.srcDir "${buildDir}/downloads/gtest"
exportedHeaders.srcDir "${buildDir}/downloads/gtest/include"
}
}
}
tasks {
linkGtestSharedLibrary.dependsOn unzipGoogleTest
createGtestStaticLibrary.dependsOn unzipGoogleTest
}
}
import de.undercouch.gradle.tasks.download.Download
task downloadGoogleTest(type: Download) {
version = '1.7.0'
src "https://googletest.googlecode.com/files/gtest-${version}.zip"
dest new File(buildDir, "downloads/gtest-${version}.zip")
outputs.file dest
}
task unzipGoogleTest(dependsOn: downloadGoogleTest) {
def dest = new File(buildDir, 'downloads/gtest')
inputs.file downloadGoogleTest.dest
outputs.dir dest
doLast {
copy {
from zipTree(downloadGoogleTest.dest)
into "${buildDir}/downloads"
}
new File(downloadGoogleTest.dest.path[0..-5]).renameTo(dest)
}
}