Idea plugin overwrites 'compile' dependencies with 'provided'

At some point in the process of generating .iml files, Gradle seems to deduplicate dependencies such that if a dependency is present in multiple scopes, only one of them is actually emitted into the XML. This sounds fine in itself (although IntelliJ is perfectly capable of handling multiple module library entries for the same dependency), but there’s an edge case when transitive dependencies get involved.

Concretely, I want to use the Immutables-gson annotation parser, which pulls in some transitive dependencies that need to be present at runtime. The annotation processor itself, however, is needed only at compile time. To address this I’ve created a ‘processor’ configuration, added it to the PROVIDED scope, and added the immutables-gson library to that configuration, then added the required runtime dependency to the ‘compile’ configuration. The expectation is that either the transitive dependency will be present in both the ‘provided’ and ‘compile’ scopes, or the ‘compile’ scope will override. However, the only entry present in the XML is for the ‘provided’ scope.

There is a workaround, which is to just use ‘compile’ for everything, but this is somewhat inelegant as it leaves the processor jars lying around in downstream projects depending on this one.
The desired behavior would be to either (1) allow dependencies to be present in multiple scopes in the emitted XML, or (2) change the resolution such that if a dependency is both ‘provided’ and ‘runtime’ it ends up as ‘compile’ (since ‘compile’ is effectively the sum of the two).

1 Like

Another workaround is to exclude those transitive dependencies of annotation parser that also exist in the ‘compile’ configuration.