Hi! Is there a way to conditionally add an artifac...
# community-support
a
Hi! Is there a way to conditionally add an artifact to a configuration depending if the outputting task is skipped or not? Edit: Probably to rephrase, how can we ensure that artifacts in the configuration will only contain file paths that exists?
Copy code
val onlyIf = project.provider {
    // Expensive operation we don't want in configuration phase
    false
}

val maybePresent = tasks.register("maybePresent") {
    val task = this
    task.onlyIf { onlyIf.get() }
    task.outputs.file(task.project.layout.buildDirectory.file("maybe.yaml"))
    doLast {
        task.outputs.files.singleFile.writeText("Key:Maybe")
    }
}

val resolvable by configurations.creating {
    isCanBeResolved = true
}

artifacts.add(resolvable.name, maybePresent) // Is there a way to conditionally add this based on onlyIf?