Reputation: 1935
I added 3 configurations to Gradle flavors. And I add some zip dependencies to them. I unzip this zip file after preBuild. The problem is my unzip task always executes even gradle file or dependencies not changed. This unzip task takes time and I'm developing ndk application. Every time when I change my static libraries with my unzip task, gradle thinks that libraries changed so it build again.
I want to block execution of unzip task if gradle file not changed. This looks like a little cache mechanism. Here is my gradle task.
dependencies {
compile "com.google.android.gms:play-services:9.4.0"
compile 'com.android.support:multidex:1.0.0'
compile 'com.android.support:appcompat-v7:24.+'
compile 'com.android.support:design:24.+'
compile fileTree(dir: 'src/main/libs', include: ['*.jar'])
alphaCompile 'my alpha release static library from private maven repository in zip type'
betaCompile 'my beta release static library from private maven repository in zip type'
prodCompile 'my prod release static library from private maven repository in zip type'
}
task unzip(group: "Static Libraries", description: "Unzip all static libraries") {
doFirst{
// get zip files from configurations
// unzip and move static libraries to destination folder
}
}
}
preBuild.finalizedBy (unzip)
Upvotes: 2
Views: 203
Reputation: 47239
It's hard to give you an exact answer because you have excluded the code in your doFirst
block, but it looks like you could leverage the Copy
task if you are just getting configuration files and then unzipping them somewhere else:
tasks.create('unzip', Copy) {
dependsOn configurations.alphaCompile
from {
project.configurations.alphaCompile.collect { zipTree(it) }
}
into project.file("${project.buildDir}/unzipDir/")
}
If you do need to define a custom task, you need to register inputs and outputs during the configuration phase by using Task.getInputs()
and Task.getOutputs()
so that Gradle can check from before execution.
Upvotes: 1