Attaching Java source jar with a FileCollection dependency

I’ve been attempting to add a dependency that is computed at compile-time (and no - artifact transforms cannot be used) through a plugin.

In the past I’ve been using a plain FileCollection and using that as the dependency notation. Works great, but sources won’t be available in the IDE even if the sources jar is present in that collection. So, naturally I tried to implement “SelfResolvingDependencyInternal” myself but the “dependencies” task is complaining about it not being able to map that dependency. Extending DefaultSelfResolvingDependency instead of AbstractDependency will fix the issue with the task but did not resolve the issue I had with sources not attaching in my IDE (eclipse). I don’t think you can set the Usage and DocsType attributes (which I guess would fix the issue) manually since DefaultSelfResolvingDependency does not implement HasAttributes.

ModuleDependency on the other hand seems to implement HasAttributes, but I believe these dependencies are not meant to be used for self-resolving dependencies (since they don’t have a resolve method like self resolving dependencies). But of course I could be wrong there. Did not try out that route out yet.

Another option would be to publish the artifacts to a maven repo but that leaves the question of how

  • A) I publish these artifacts
  • B) I consume these artifacts (I’d somehow need to add a repository that is used to lookup the artifacts)

So what should I do? Google was extremely unhelpful

As a workaround I instead opted for using a FlatDir repository (via project.getRepositories().flatDir()) and adding the jars within the repo.
The IDE now picks up on the sources jar if they are stored according (i.e. artifactid-version-sources.jar)