Gradle 始终执行任务
Gradle always executes task
我为 Gradle 口味添加了 3 种配置。我向它们添加了一些 zip 依赖项。我在 preBuild 之后解压这个 zip 文件。
问题是我的解压缩任务总是执行甚至 gradle 文件或依赖项没有改变。这个解压缩任务需要时间,我正在开发 ndk 应用程序。每次当我用我的解压任务改变我的静态库时,gradle 认为库改变了所以它重新构建。
如果 gradle 文件未更改,我想阻止执行解压缩任务。这看起来像一个小小的缓存机制。这是我的 gradle 任务。
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)
很难给你一个确切的答案,因为你已经排除了你的 doFirst
块中的代码,但看起来你可以利用 Copy
任务,如果你只是获取配置文件和然后将它们解压缩到其他地方:
tasks.create('unzip', Copy) {
dependsOn configurations.alphaCompile
from {
project.configurations.alphaCompile.collect { zipTree(it) }
}
into project.file("${project.buildDir}/unzipDir/")
}
如果您确实需要定义自定义任务,则需要在 configuration phase by using Task.getInputs()
and Task.getOutputs()
期间注册输入和输出,以便 Gradle 可以在执行前进行检查。
我为 Gradle 口味添加了 3 种配置。我向它们添加了一些 zip 依赖项。我在 preBuild 之后解压这个 zip 文件。 问题是我的解压缩任务总是执行甚至 gradle 文件或依赖项没有改变。这个解压缩任务需要时间,我正在开发 ndk 应用程序。每次当我用我的解压任务改变我的静态库时,gradle 认为库改变了所以它重新构建。
如果 gradle 文件未更改,我想阻止执行解压缩任务。这看起来像一个小小的缓存机制。这是我的 gradle 任务。
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)
很难给你一个确切的答案,因为你已经排除了你的 doFirst
块中的代码,但看起来你可以利用 Copy
任务,如果你只是获取配置文件和然后将它们解压缩到其他地方:
tasks.create('unzip', Copy) {
dependsOn configurations.alphaCompile
from {
project.configurations.alphaCompile.collect { zipTree(it) }
}
into project.file("${project.buildDir}/unzipDir/")
}
如果您确实需要定义自定义任务,则需要在 configuration phase by using Task.getInputs()
and Task.getOutputs()
期间注册输入和输出,以便 Gradle 可以在执行前进行检查。