Is there a trick I can use to lazily configure publication details

I am currently writing a plugin to download some jars from a 3rd party vendor site, extract some information from their manifest, enrich with handcrafted dependency metadata and publish as Maven artifacts to our repo.

My problem is that I don’t know the version of the publication until I actually download the jar, as I need to get it from the manifest (the jars always have the same name). I also extract from the manifest a few more tidbits like the org name and description.

As the MavenPublication does not let me specify closure to lazy-evaluate all these properties, what I do currently is that I check the StartParameters and only add the publications if the ‘publish’ task is explicitly requested.

That feels quite hacky, especially as I have most of the information about the publication, except these few details coming from the manifest.

Trying to get some attention.

There currently isn’t an really a better solution to do this. When you have configuration that is expensive to perform, in this case downloading a remote artifact, and want to defer it unless its required you have basically two options:

  1. Create a ‘configurer task’ which performs the given configuration at execution time.
  2. Conditionally perform the configuration by checking if a given task is going to run (typically using TaskExecutionGraph.hasTask().

Option 1 won’t work in your case because the publishing extension is a @DeferredConfigurable so it can’t be mutated at execution time. So you’re stuck with option 2, which is essentially what you are already doing.