I’m trying to publish a custom component in my plugin using SoftwareComponentFactory.adhoc()
. I have created a variant using an outgoing configurations which contains an artifact. This artifact is built by a task, which transitively depends on a resolvable configuration, which contains external module dependencies. Is Gradle supposed to figure out that the variant depends on these external module dependencies and to list them as dependencies in the Maven POM and the Gradle module metadata when publishing? If not, how would I get Gradle to do this?
Here are some details on how everything is wired together:
- attaching an artifact to the outgoing configuration
project.getArtifacts().add(hdvlSourcesArchiveElements.getName(), hdvlSourcesArchive.getArchiveFile(), artifact -> {
artifact.builtBy(hdvlSourcesArchive);
});
// hdvlSourcesArchiveElements is an outgoing configuration
// hdvlSourcesArchive is a Zip task which indirectly depends on the resolvable configuration
- tie
hdvlSourcesArchive
to task that depends on resolvable configuration
project.getTasks().register("hdvlSourcesArchive", Zip.class, zip -> {
zip.from(writeDependenciesFile.getDestination(), it -> {
it.into(".gradle-hdvl");
});
// ... configuration of the output file location
});
// writeDependenciesFile is a task that just prints out the names of the files resolved from the configuration
- configure
writeDependenciesFile
task to depend on resolvable configuration
project.getTasks().register("writeDependenciesFile", WriteDependenciesFile.class, writeDependenciesFile -> {
writeDependenciesFile.getXrunArgsFiles().from(project.getConfigurations().getByName("xrunArgsFiles"));
// ... configuration of output file location
});
// xrunArgsFile is a resolvable configuration that extends a declarable configuration
When I call the hdvlSourcesArchive
task, I see Gradle resolve the configuration and call writeDependenciesFile
.
I enable Maven publishing using an adhoc component:
AdhocComponentWithVariants hdvlLibrary = softwareComponentFactory.adhoc("hdvlLibrary");
project.getComponents().add(hdvlLibrary);
hdvlLibrary.addVariantsFromConfiguration(hdvlSourcesArchiveElements, configurationVariantDetails -> {});
mavenPublication.from(hdvlLibrary);
When publishing to a Maven repository, I see the zip produced by hdvlSourcesArchive
being uploaded, a POM being created and a Gradle metadata file. The POM and the metadata files don’t contain any information about the external module dependencies that are used.