The what:
I am trying to make a Gradle plugin that manages an extra source between multiple projects. For simplicity’s sake, I made a producer and a consumer plugin, though they really could have been the same plugin class.
I am trying to make it so the dependencies of my java project already declared for compilation are used for the inputs to the consumer
The why:
The big goal with this plugin is to avoid as much manual configuration as possible for developers. I would rather the plugin be doing more heavy lifting, even if the plugin becomes extra complex as a result.
Details:
The producer plugins’ job is to create a Zip containing the generated code and publish the zip file. I make use of the distribution plugin to do that. I set an attribute to distinguish the zip file as a specific variant. The producer seems to be working well, I produce a zip, it is published, and attached to the Java software component. The Gradle module metadata file shows my zip file has the correct variant information.
The consumer’s job is to extract the zip file from the producer, and then run a code generation task. I have a dependsOn declaration between the code generation task and the extraction task. I managed to select the artifact dependencies I needed by using a lenient artifact view from the configuration I want to pull from. This works great in a repo containing a single project. It unfortunately falls apart when a consumer wants to use the output of a project that applied the producer plugin. The extraction task in the consumer tries to run before the distZip task runs in the producer, and so the consumer fails with an error saying the zip file doesn’t exist.
I know it’s bad practice (and maybe illegal in the version of Gradle I am using, 8.10) to depend on tasks from another project, but that’s effectively what I want to happen.
I did see the section in the docs saying to make a configuration in the producer and have the consumer depend on that project for that configuration.
I couldn’t get that to work programmatically and again, I don’t want developers to have to duplicate their dependencies.
Any help would be appreciated, and I’m open to feedback on the approach as well as just specific how-to info. Thanks in advance!