I am writing a custom task that essentially post-processes the result of the standard jar task. I also have a plugin that creates an instance of that task, as well as a custom configuration. Now I want to add the output of my custom task as an artifact of my custom configuration. The problem is that, just like the standard jar task, the output file name of the task is dynamic; it may change during project configuration. But the ArtifactHandler does not provide any way to specify a dynamic file name as an artifact. The standard jar task can get around this because ArtifactHandler special cases the AbstractArchiveTask, so that the output of such tasks that have been added as artifacts is read during execution instead of configuration. But since my task is not an AbstractArchiveTask, it cannot use that functionality.
It seems to me that instead of special casing AbstractArchiveTask, the ArtifactHandler should simply allow any task to be added to a configuration’s artifacts, and read the outputs.files of that task during execution.
The only workaround I have found is to use afterEvaluate in my plugin to add the artifact after the project has been configured. But that is extremely brittle (what if the project removes or alters the default task during configuration?), and also does not give the project the option of removing the artifact during configuration. Is there a better way to achieve this?