I'd like to detect duplicate publications (in term...
# community-support
m
I'd like to detect duplicate publications (in terms of artifacts) in a convention plugin. (E.g. multiple publications including the same toml.) To avoid
afterEvaluate
, I tried to listen to publications as they are defined with
publishing.publications.configureEach {}
however, I found out that a publication's artifacts need not be known/defined when the publication is added. Next, I tried
publication.artifacts.configureEach {}
but this eventually results in strange errors about metadata. I looked a bit around, and I believe
publication.artifacts
is currently not "lazy enough", so that when I do
publication.artifacts
, it eagerly populates something too early, resulting in problems later on. I'm not sure if
afterEvaluate
would really help here. Any other suggestions how to detect duplicate publications reliably?
v
Maybe some verification task that does the check at execution time and is wired to
check
?
m
Thanks, I can indeed detect the publication conflict, say via a new task at execution time. So at least I could crash the build. Next, I'd like to also implement a publication preference, so e.g., if I detect conflicting publications A and B, I'd like to disable B, effectively by disabling all publishBTo... tasks related to B. Is it possible to do this while keeping CC compatibility? E,g., I tried to define a
conflictingPublications
provider at the script level, returning a
List<String>
, then redefining it inside tasks
withType<AbstractMavenPublishTo>
(so as to avoid capturing the script reference), then using the list inside an
onlyIf
block in each task. But this fails with "the value of this property has been discarded during serialization". Is there a way to fix this? Ideally the list of publications to disable should be computed only once.
I think the problem is that the `publication`in publish tasks is transient and not serialized. It seems to work if I provide that one as well.