简体   繁体   English

gradle没有激活任务来复制文件

[英]gradle not excuting task to copy files

I am using following code in build.gradle that copies different configuration files for airship. 我在build.gradle中使用以下代码来复制飞艇的不同配置文件。 However what I am finding is my tasks copyReleaseConfigFileTask / copyDebugConfigFileTask are not being called. 但是我发现的是我的任务copyReleaseConfigFileTask / copyDebugConfigFileTask没有被调用。 Can anyone give hints as to why the tasks I have defined below are not getting executed? 任何人都可以提供一些提示,说明为什么我在下面定义的任务没有被执行?

task copyReleaseConfigFileTask(type: Copy) << {
    println "-> using airship release config"
    from 'app/src/main/assets/airshipconfig.properties.release'
    into 'app/src/main/assets/airshipconfig.properties'
}

task copyDebugConfigFileTask(type: Copy) << {
    println "-> using airship debug config"
    from 'app/src/main/assets/airshipconfig.properties.debug'
    into 'app/src/main/assets/airshipconfig.properties'
}

assembleDebug {
    dependsOn copyDebugConfigFileTask
}

assembleRelease {
    dependsOn copyReleaseConfigFileTask
}

First of all, you didn't properly configured your tasks. 首先,您没有正确配置任务。 You've tried to make CopySpecification configuration in the execution phase, though it has to be done at configuration phase. 您已尝试在执行阶段进行CopySpecification配置,但必须在配置阶段完成。 To achieve this, you have to delete << from your task specification. 要实现此目的,您必须从任务规范中删除<< It has to be rewritten this way: 它必须以这种方式重写:

task copyReleaseConfigFileTask(type: Copy) {
    doLast {
         println "-> using airship release config"
    }
    from 'app/src/main/assets/airshipconfig.properties.release'
    into 'app/src/main/assets'
    rename('airshipconfig.properies.release','airshipconfig.properties')
}

task copyDebugConfigFileTask(type: Copy) {
    doLast {
        println "-> using airship debug config"
    }
    from 'app/src/main/assets/airshipconfig.properties.debug'
    into 'app/src/main/assets'
    rename('airshipconfig.properties.debug','airshipconfig.properties')
}

Note, << is the same as a doLast closure. 注意, <<doLast闭包相同。 So, this will properly configure your copy tasks, but the message will appear only after execution. 因此,这将正确配置您的复制任务,但该消息将仅在执行后出现。

One more, you've provided an into value as path with file name, but it has to be a path to the directory, not a file. 还有一个,你提供了一个into值作为带文件名的路径,但它必须是目录的路径,而不是文件。 To rename it, use a rename closure additionally. 要重命名它,请另外使用rename闭包。 Read about it in the official CopySpec API 在官方CopySpec API中阅读它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM