This message was deleted.
# community-support
s
This message was deleted.
c
Perhaps something like this (Kotlin, adjust logic as appropriate):
Copy code
private fun Project.configureRepoPublishing() {
        // only enable publishing tasks for certain repos
        tasks.withType<PublishToMavenRepository>().configureEach {
            onlyIf(
                providers.ciBuild().map {
                    when {
                        it -> when {
                            isSnapshotVersion() -> repository.isSnapshotRepo()
                            else -> repository.isReleaseRepo()
                        }
                        else -> repository.isLocalRepo()
                    }
                }
            )
        }
    }
s
Yup, doing something similar right now. However this can be misleading to a user? If someone were to try publishing a snapshot to a release repo. The build would be successful but the publishing task would be skipped.
c
perhaps, though most times publishing is handled by CI builds, `publish`task handles all that are available to publish. If user interaction is a concern you could add a doFirst to disabled tasks to throw an exception.
mmm. perhaps not, if the tasks are disabled they won’t execute doFirst.
s
That's fair. This would be handled at CI and I would not expect a user to be calling this manually.
👍 1
For some reason I assumed that this feature would exist 😅 . It makes sense to be able to disable tasks which are invalid in a particular project.
c
the feature does exist, in a general sense, via
onlyIf
or
enabled
on any given task.
v
Or
doFirst
if you want a failure instead.
s
Thanks! These two approaches would help. I also wanted to ask about what would be an idiomatic gradle way of doing this? If I wanted to not expose certain functionality to gradle users and hence want to disable certain combination of tasks based on requirements, is that a valid usecase vs does Gradle recommend an alternative way of dealing this kind of requirement.
I ask this because I've not really come across a plugin that tells me certain tasks are not allowed or disabled etc. A possible solution could be to prevent configuration of such tasks. but that can only happen if the plugin source is under my control.
v
The idiomatic way would probably be to not add the task if possible, or otherwise to disable it if you don't need lazy logic, or to use
onlyIf
if you need delayed logic.