Вопрос

A certain amount of Gradle tasks I wrote, don't need any in- or output. Because of that, these tasks always get the status UP-TO-DATE when I call them. An example:

task backupFile(type: Copy) << {
    //Both parameters are read from the gradle.properties file
    from file(adjusting_file.replaceAll("\"", "")) 
    into file(backupDestinationDirectory + "/main/")

    println "[INFO] Main file backed up"
}

Which results in the following output:

:gradle backupFile
:backupFile UP-TO-DATE

Is there a way to force a(ny) task to execute, regardless of anything? If there is, is it also possible to toggle task execution (e.g. telling the build script which tasks to run and which tasks to ignore)?

I can't omit the << tags, as that would make the tasks to always execute, which isn't what I desire.

Many thanks in advance for your input.

Это было полезно?

Решение

Tasks have to be configured in the configuration phase. However, you are configuring it in a task action (<< { ... }), which runs in the execution phase. Because you are configuring the task too late, Gradle determines that it has nothing to do and prints UP-TO-DATE.

Below is a correct solution. Again, I recommend to use doLast instead of << because it leads to a more regular syntax and is less likely added/omitted accidentally.

task backupFile(type: Copy) {
    from file(adjusting_file.replaceAll("\"", "")) 
    into file(backupDestinationDirectory + "/main/")
    doLast {
        println "[INFO] Main file backed up"
    }
}    

Другие советы

I have been trying to do this for many days. I have to create many intermidate jars on the processResource step. Following one needs to be created on the processResource step.

processResources.dependsOn(packageOxygenApplet)  //doesn't work

task packageOxygenApplet (type: Jar) {

    println '** Generating JAR..: ' + rsuiteOxygenAppletJarName
        from(sourceSets.main.output) {
            include "org/worldbank/rsuite/oxygen/**"
        }
        baseName = rsuiteOxygenAppletJarName

        manifest {
            attributes("Build-By": oxygenUsername,
                "Specification-Title": "Oxygen World Bank Plugin")
        }
        destinationDir = file("src/main/resources/WebContent/oxygen")

}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top