Clean task does not clear the specified outputs.file

I wrote a build.gradle script to automatically load the carousel from a given url. The file is then unpacked, leaving only the mancenter.war and the initial zip file in the destination directory. Later this war file is taken for reference to the pier.

However, although I have defined outputs.file for my two tasks, the files are not cleaned up when running gradle clean. Thus, I would like to know what I need to do so that the downloaded and unpacked files get deleted when doing gradle clean. Here's my script:

By the way, if you have any recommendations for improving the script, please feel free to tell me!

apply plugin: "application"

dependencies {
    compile "org.eclipse.jetty:jetty-webapp:${jettyVersion}"
    compile "org.eclipse.jetty:jetty-jsp:${jettyVersion}"
}

ext {
    distDir = "${projectDir}/dist"

    downloadUrl = "http://download.hazelcast.com/download.jsp?version=hazelcast-${hazelcastVersion}"
    zipFilePath = "${distDir}/hazelcast-${hazelcastVersion}.zip"
    warFilePath = "${distDir}/mancenter-${hazelcastVersion}.war"

    mainClass = "mancenter.MancenterBootstrap"
}

task downloadZip() {
    outputs.file file(zipFilePath)
    logging.setLevel(LogLevel.INFO)
    doLast {
        ant.get(src: downloadUrl, dest: zipFilePath)
    }
}

task extractWar(dependsOn: downloadZip) {
    outputs.file file(warFilePath)
    logging.setLevel(LogLevel.INFO)
    doLast {
        ant.unzip(src: zipFilePath, dest: distDir, overwrite:"true") {
            patternset( ) {
                include( name: '**/mancenter*.war' )
            }
            mapper(type:"flatten")
        }
    }
}

task startMancenter(dependsOn: extractWar, type: JavaExec) {
    main mainClass
    classpath = sourceSets.main.runtimeClasspath
    args warFilePath
}

      

UPDATE

I found a link that describes how to provide additional deletion locations when calling a clean task. Basically, you can do this. eg:

clean{
    delete zipFilePath
    delete warFilePath
}

      

+3


source to share


2 answers


I got confirmation from the source that the clean task is just deleting the build directory. This assumes that you want to clear everything, and that all the outputs of the task are located somewhere in this build directory.



So the simplest and best practice is to just store the outputs somewhere in the build directory.

+5


source


You can add tasks to clean up as follows:

clean.dependsOn(cleanExtractWar)
clean.dependsOn(cleanDownloadZip)

      



cleanTaskName is a virtual task that will clear all outputs for TaskName.

+3


source







All Articles