Completely disabling a gradle task prior to Configuration or otherwise suppressing task output during configuration phase

Hello everyone. I have the situation where I am using Gradle tasks to perform specific migration-relevant processes during deployment. These are run in a container during actual deployment and can be exactly reused during development, making the entire process chain a lot easier.

Specifically, I am using two plugins: Axion (axion-release-plugin) and a Kafka Schema Registry plugin (GitHub - ImFlog/schema-registry-plugin: Gradle plugin to interact with Confluent Schema-Registry.).

These export tasks and configurations which I am extending as follows:

scmVersion {
	// https://axion-release-plugin.readthedocs.io/en/latest/
	ignoreUncommittedChanges.set(true)
	useHighestVersion.set(true)
	versionIncrementer 'incrementPatch'
}

and:

schemaRegistry {
	url = System.getenv("schemaRegistryUrl") != null ? System.getenv("schemaRegistryUrl") : 'http://localhost:8081/'
    credentials {
		username = System.getenv('schemaRegistryUser') != null ? System.getenv('schemaRegistryUser') : 'user'
		password = System.getenv('schemaRegistryPassword') != null ? System.getenv('schemaRegistryPassword') : 'user'
    }
    config {
        // ...
    }

    def latestVersionsBySubject = findLatestSchemaVersions().collectEntries { key, value ->
        [(key): "${project.rootDir}/src/main/avro/${value}"]
    }

    println "Found schemas:\n" + prettyPrint(toJson(latestVersionsBySubject))

    register {
        if (!latestVersionsBySubject.isEmpty()) {
            subject(..., latestVersionsBySubject[...])
        }
    }

}

The problem is, as is often the case with Gradle, that this code is executed in the configuration phase as well. If I were creating these tasks myself, I would be able to do something like task.register(...) to make it be evaluated lazily, but since these are provided by third-party plugins, I can see no way to influence their lifecycle. In case of the Schema Registry extension, I am forced to e.g. provide a null check (if (!latestVersionsBySubject.isEmpty()) { ... }) being the files that the task requires may not necessarily be present during the configuration phase.

In the case of the Axion plugin, when I do a checkout to do a minimal build that can execute my migration tasks, I get a lot of superfluous output:

Failed to open repository, trying to work without it org.eclipse.jgit.errors.RepositoryNotFoundException: repository not found: /tmp/deleteme/table-receipts-service
Couldn't perform is legacy DefTagname Repository command on uninitialized repository
Could not resolve current position on uninitialized repository, returning default
Couldn't perform check uncommitted changes command on uninitialized repository

which is correct (there is no sane Git config available at that time), but inconsequential in that specific case. Similarly, my println "Found schemas: ..." also prints unnecessarily.

So far I have tried running my build with ./gradlew -x release (the task that e.g. Axion provides), as well as ./gradlew -Prelease.enabled=false, but neither of them seem to have any bearing on the configuration phase of the build (during which the logs are produced).

This does not fail my build, but it is noisy output that I would like to suppress somehow. The problem boils down to: there is logging happening during the configuration phase of my build that I would like to suppress via command-line flags.

Is there any way to completely disable a Gradle task’s configuration from the command line? Or otherwise suppress these logs via a command-line flag?

If configuration happens and configuration is logging, it will be logged.
Even using tasks.register would not guarantee that the configuration is not done.
Depends on all other participants behave nicely and do not break task-configuration avoidance.
If you want a commandline flag to disable that configuration, you probably just have to check for some project property that you then can set using -P ... from the commandline.

But given that subjects in register is a ListProperty, hoping it is treated lazily properly by the plugin, you could maybe just do the calculation lazily with something like

schemaRegistry {
    register {
        subjects.add(provider {
            def latestVersionsBySubject = findLatestSchemaVersions().collectEntries { key, value ->
                [(key): "${project.rootDir}/src/main/avro/${value}"]
            }

            println "Found schemas:\n" + prettyPrint(toJson(latestVersionsBySubject))

            Subject(..., latestVersionsBySubject[...], AvroSchema.TYPE)
        })
    }
}