Create POM from custom jar task

I’m converting a fairly complex Ant build progressively to Gradle. I am able to create the JAR I want to distribute (well, nearly) using a custom Jar task. I override the standard jar task in the hope subsequent phases would use it.

If I use the textbook idiom from components.java, I get a plausible POM, but the JAR I publish appears to have been made by some default jar task, created by the java-library plug-in I assume.

If I use the idiom artifact jar, the JAR is right but the POM lacks all the dependency information. I’d be grateful for suggestions how to get Gradle to provide the right POM, preferebly using the depencency information already present.

This link will land you in my gradle.build at the publication clause:
build.gradle#L612

I think that the root cause may be that the use of the jar task by the Java plug-in is “not lazy enough”. There is a comment hinting at this in the code of the JavaPlugin.java, although I can’t pretend to understand what is going on around it.

My desire for a custom jar task stemmed from the need to have it take post-processed classes (and other stuff) instead of what compileJava produces.

My work-around has been to restructure the rest of the build so that I can use the provided jar task, configured but not replaced. The jar task in components.java reads from the conventional compilation location. So it was simply :rofl: a matter of ensuring other task outputs should be diverted and only post-processed versions end up at the conventional place instead. It’s more copies but not really a worse design. Now I can use from components.java in my publication and get the POM I need by default.

Thanks to those who clicked through to the code (and are not just robots).