I am not able to avoid the following task. It alw...
# community-support
m
I am not able to avoid the following task. It always unzips. Suggestions? (using gradle 8.7)
Copy code
task unZipSource(type:Copy) {
    from(zipTree("$buildDir/v7.3.1.zip")) {
        eachFile { fcd ->
            fcd.relativePath = new RelativePath(true, fcd.relativePath.segments.drop(1))
        }
    }
    destinationDir projectDir
	inputs.file("$buildDir/v7.3.1.zip")
	outputs.file("$projectDir/AUTHORS")
    dependsOn downloadSource
}
m
What task are you requesting?
m
I would like this task to know it has already unzipped, and therefore not unzip again on each execution.
... unzipped in a previous execution/build.
My impression was that by specifying "AUTHORS" as an output file, that gradle would see that the file existed and therefore not need to unzip again.
m
Oh ok 👍 The task is never up-to-date in Gradle terminology
I believe you're just adding one extra output (in addition to destinationDir)
If you run Gradle with
-i
it will show you why the task is not up-to-date
m
Thanks. It is working now without changes. My guess is that the original build ran as user "root" and the subsequent build did not. Two executions as root work. My apologies.
👍 1
v
What you do is a very bad idea though, unless that task is a pure manual "do this now task" and not something that runs during normal build.
You define the project directory as output directory, that means each and every file in your project directory is considered output of that task. And you have thus also overlapping outputs between this task and practically all other tasks which causes a shitload of problem you don't want to have.
Better do not specify a
type
and instead use
copy { ... }
inside a
doLast { ... }
action and declare the input and output file properly, then you should hopefully get the result you intended.
m
Not my scenario. The official build process is via a docker container that uses a shared folder/mount on my computer. I was attempting to modify one file and rebuild with the hope that the unzip would not overwrite my change. Otherwise the build was run as normal ... just my user instead of docker's root.
I will look at your second paragraph more carefully.
v
Besides that, any explicit
dependsOn
where you do not have a lifecycle task on the left-hand side is a code smell and a sign that you do something wrong, like not wiring task output to task inputs, but configuring paths manually which you shouldn't do
m
Basically doing both: wiring tasks and input/outputs. Likely smells horrible.
Initially wired tasks to get process, then added input/outputs to get things skipped on rerun.
v
Assuming that zip is the sole output of that download task, you probably want something like
Copy code
task unZipSource {
	inputs.files(downloadSource)
	outputs.file("$projectDir/AUTHORS")
    doLast {
        copy {
            from(zipTree(downloadSource.outputs.files.singleFile)) {
                eachFile { fcd ->    
                    fcd.relativePath = new RelativePath(true,     fcd.relativePath.segments.drop(1))
                }
            }
        }
        destinationDir projectDir
    }
}
or something along those lines.
m
Ok. Will copy/paste and examine during next big compile. This is C++ stuff building library via third party's cmake architecture.