Hi, if I understand correctly tasks are up-to-date...
# community-support
s
Hi, if I understand correctly tasks are up-to-date if the build scripts didn't change and will not execute if all outputs exist. but I want to force execution if there is a property in the command line, for example i have -PbuildProfile=p233/p241 etc. currently i need to clean before building with a different profile. is there a way i can cause re-execution of tasks if buildProfile has changed since the last run? or maybe force clean if buildProfile has changed since the last run?
v
You do not understand correctly - not fully šŸ™‚
A task is up-to-date if all it's inputs are unchanged (the build script and build script classpath also being inputs) and the outputs are also unchanged. As soon as you modify an input, or modify or delete an output, the task is no longer up-to-date. If the task behaves differently if the property is set differently, but does not re-execute, then the inputs of the task are not configured correctly.
You can ad-hoc do it in the runtime api via
inputs.property(...)
for any task for example.
s
I have this task, it does not re-execute if i run with different profile. the prepare task which it depends on does run and prepares a new environment, but the dotnet command does not run, the dll is not changed. how to use inputs.property(...) ? it wants a value but i don't care about the value i only care that its changed
Copy code
val compileDotNet = create("compileDotNet") {

    outputs.file(digmaDll)
    outputs.file(digmaPbd)

    dependsOn(prepare)

    doLast {
        exec {
            executable = "dotnet"
            args = listOf(
                "msbuild",
                solutionFile,
                "/p:Configuration=$buildConfiguration",
                "/t:Restore;Rebuild"
            )
            workingDir = projectDir
        }
    }
}
v
How should it know whether the value changed if you don't give it the value? So give it the value and it can know. Btw., some remarks if you're interested: • don't use
create
but
register
to leverage task-configuration avoidance • you can use
by creating
or
by registering
to take the name from the variable name instead of duplicating it • explicit
dependsOn
(except with a lifecycle-task on the left-hand side) is practically always a code-smell, instead you should wire task outputs to task inputs to get the necessary task-dependencies automatically implicitly • why do you not use a task of type
Exec
instead if all you want to do is
exec { ... }
? • the project dir should be the default working dir anyway if I'm not completely mistaken • you declare outputs on your task but not any inputs. are there really no inputs to that task? what about
solutionFile
? or files it then references or compiles or whatever that command does? Each and every file or property that is influencing the outcome of the task must be declared as input, or the up-to-date checks do not work and you could also not safely make the task cacheable but would get semantically corrupted cache entries and false-hits.
s
@Vampire Thank you, i will do register instead of create, I usually do but this is an old task. I understand , i added an input
Copy code
inputs.file(pluginPropsFile)
pluginPropsFile is a file that changed between profiles and it does what i want. I understand what you mean with inputs and outputs, i will do it. Thank you!
šŸ‘Œ 1
v
If that is what
prepare
generates and
prepare
properly declares it as output, just do
inputs.files(tasks.prepare)
and remove the manual
dependsOn
šŸ™‚
s
I did it and it works! Thank you!
šŸ‘Œ 1