Javi
08/16/2025, 2:51 PM* What went wrong:
A problem occurred configuring project ':semver-gradle-plugin'.
> Failed to notify project evaluation listener.
> Cannot mutate the hierarchy of configuration ':semver-gradle-plugin:apiElements' after the configuration was published as a variant. After a configuration has been observed, it should not be modified.
> Gradle Module Metadata can't be modified after an eagerly populated publication.
Javi
08/16/2025, 3:42 PMprivate fun removeDuplicatedPublications() {
configure<PublishingExtension> {
publications.withType<MavenPublication>().configureEach { publication ->
if (publication.name == "maven") {
val distinctArtifacts: List<MavenArtifact> =
publication.artifacts.distinctBy { artifact -> artifact.classifier }
publication.artifacts.clear()
publication.artifacts.addAll(distinctArtifacts)
}
}
}
}
Javi
08/16/2025, 4:19 PMprivate fun removeDuplicatedPublications() {
configure<PublishingExtension> {
publications.withType<MavenPublication>().whenObjectAdded { publication ->
if (publication.name == "maven") {
val distinctArtifacts: List<MavenArtifact> =
publication.artifacts.distinctBy { artifact -> artifact.classifier }
publication.artifacts.clear()
publication.artifacts.addAll(distinctArtifacts)
}
}
}
}
Javi
08/16/2025, 5:20 PMVampire
08/16/2025, 5:23 PMall
instead to remove the ordering constraint.Javi
08/16/2025, 5:23 PMall
too, but it does not workJavi
08/16/2025, 5:25 PMwhenObjectAdded
was fixing the error generated by Gradle 9.0.0, but the artifacts that were duplicated were not being correctly deleted, so it was generating task dependencies issuesVampire
08/16/2025, 5:25 PMpublications.withType<MavenPublication>().named { it == "maven" }...
instead of matching all and filtering inside.Javi
08/16/2025, 5:25 PMVampire
08/16/2025, 5:26 PMconfigureEach
, sure, there should be no change in behaviorJavi
08/16/2025, 5:26 PMall
Vampire
08/16/2025, 5:27 PMJavi
08/16/2025, 5:28 PMJavi
08/16/2025, 5:28 PMJavi
08/16/2025, 5:29 PMnamed("maven")
generates the issue (if not all
would work)...Vampire
08/17/2025, 9:24 AMIs it possible to "clone" the publication, remove the initial one. Modify the cloned one without the duplicated artifacts, and add it?
Most probably not. And even if it were, you write says you try to modify it after it was used for something already, do that would probably be a very bad idea.
In any case, callinggenerates the issue (if not all would work)...named("maven")
named("maven")
(eager) != named { it == "maven" }
(lazy).
But anyway, if it fails with named("maven")
, then it means that at the time you call this the publication is already registered and also already used, so no matter what code you use will not work.
This would for example be the case when you call that in an afterEvaluate
while the code that used that publication also run in an earlier afterEvaluate
or similar. But hard to say without an MCVE what the actual problem might be.Javi
08/17/2025, 10:15 AM