Caleb Cushing
12/29/2025, 5:52 PMChris Lee
12/29/2025, 5:58 PMMartin
12/29/2025, 6:00 PMtasks.register("foo")
tasks.configureEach {
if (name == "foo") {
// Gradle fails here
tasks.register("bar")
}
}
But this doesn't work.Martin
12/29/2025, 6:01 PMCaleb Cushing
12/29/2025, 6:01 PMCaleb Cushing
12/29/2025, 6:01 PMMartin
12/29/2025, 6:02 PMMartin
12/29/2025, 6:02 PMMartin
12/29/2025, 6:02 PMMartin
12/29/2025, 6:04 PMtasks.register("foo")
val bar = tasks.register("bar")
bar.configure { isEnabled = false }
tasks.configureEach {
if (name == "foo") {
bar.configure {
dependsOn(this@configureEach)
isEnabled = true
}
}
}Philip W
12/29/2025, 6:55 PMpluginManager.withPlugin instead.Philip W
12/29/2025, 6:56 PMCaleb Cushing
12/29/2025, 6:57 PMtasks
.withType(PublishToMavenRepository.class)
.stream()
.filter(task -> task.getName().startsWith("publishMavenPublicationTo"))
.toList()
.forEach(task -> {
var repository = task.getRepository();
tasks.register(repository.getName() + "ArtifactPath", ArtifactPathTask.class, t -> {
t.getDirectory().set(project.getLayout().dir(project.provider(() -> new File(repository.getUrl()))));
t.getProjectName().set(project.getName());
t.getProjectGroup().set(project.getGroup().toString());
t.getProjectVersion().set(project.provider(project.getVersion()::toString));
});
});Caleb Cushing
12/29/2025, 6:58 PMPhilip W
12/29/2025, 6:59 PMPhilip W
12/29/2025, 6:59 PMCaleb Cushing
12/29/2025, 6:59 PMCaleb Cushing
12/29/2025, 6:59 PMPhilip W
12/29/2025, 7:00 PMPhilip W
12/29/2025, 7:01 PMPhilip W
12/29/2025, 7:01 PMPhilip W
12/29/2025, 7:01 PMCaleb Cushing
12/29/2025, 7:02 PMPhilip W
12/29/2025, 7:02 PMCaleb Cushing
12/29/2025, 7:03 PMPhilip W
12/29/2025, 7:08 PMpluginManager.withPlugin("maven-publish") {
val publishExtension = extensions.getByType<PublishingExtension>()
publishExtension.repositories.withType<MavenArtifactRepository>().configureEach {
}Martin
12/29/2025, 7:17 PMMartin
12/29/2025, 7:20 PMMartin
12/29/2025, 7:20 PMPhilip W
12/29/2025, 7:20 PMMartin
12/29/2025, 7:20 PM.configureEach {}, right?Philip W
12/29/2025, 7:21 PMMartin
12/29/2025, 7:21 PMforEach{} and all collection APIs are verbotenPhilip W
12/29/2025, 7:22 PMPhilip W
12/29/2025, 7:23 PMMartin
12/29/2025, 7:23 PM.all{} is on both NamedDomainObjectContainer and Iterable<T> so depending your compile type, it will do things Philip W
12/29/2025, 7:24 PMMartin
12/29/2025, 7:24 PMMartin
12/29/2025, 7:24 PM.all {} is eager but live on a NamedObjectContainerMartin
12/29/2025, 7:24 PMPhilip W
12/29/2025, 7:25 PMThis method is a terminal eager operation. It will cause the realization of all elements of this collection.Martin
12/29/2025, 7:25 PMMartin
12/29/2025, 7:26 PMPhilip W
12/29/2025, 7:26 PMPhilip W
12/29/2025, 7:27 PMMartin
12/29/2025, 7:28 PMtasks.all {
println("${it.name}")
true
}
tasks.register("foo")
This prints("foo")Martin
12/29/2025, 7:28 PM(tasks as Iterable<Task>).all {
println("${it.name}")
true
}
tasks.register("foo")
This doesn'tMartin
12/29/2025, 7:29 PMMartin
12/29/2025, 7:30 PMMartin
12/29/2025, 7:35 PMPhilip W
12/29/2025, 7:35 PMPhilip W
12/29/2025, 7:36 PMPhilip W
12/29/2025, 7:37 PMMartin
12/29/2025, 7:37 PMPhilip W
12/29/2025, 7:37 PMall won't contain/realize the new elements.Martin
12/29/2025, 7:38 PMMartin
12/29/2025, 7:38 PMCaleb Cushing
12/29/2025, 7:39 PMCaleb Cushing
12/29/2025, 7:40 PMPhilip W
12/29/2025, 7:42 PMCaleb Cushing
12/29/2025, 7:55 PMCaleb Cushing
12/29/2025, 7:56 PMPhilip W
12/29/2025, 7:59 PMtasks.named("publishMavenPublicationTo" + name) and the providersPhilip W
12/29/2025, 7:59 PMCaleb Cushing
12/29/2025, 8:00 PMPhilip W
12/29/2025, 8:04 PMCaleb Cushing
12/29/2025, 8:06 PMPhilip W
12/29/2025, 8:10 PMparse? You can just use URI.getScheme, but yeah, you need to "parse" the scheme or just check if the scheme is http/httpsCaleb Cushing
12/29/2025, 8:12 PMefemoney
12/30/2025, 3:35 PMVampire
12/30/2025, 5:41 PMregister within someTasks.configureEach does not work (if task-configuraton avoidance is not broken) as the closure is called too late to register a new task, but you could still use create instead of register within the configureEach.