rules_scala icon indicating copy to clipboard operation
rules_scala copied to clipboard

Compiler dependencies with plus one and strict deps

Open liucijus opened this issue 4 years ago • 4 comments

In some cases Scala compiler needs some deps to be on the classpath, which are not directly mentioned in the source code of the target. Such deps should come transitively with plus-one. Otherwise it is a coupling on the client side, which will will break if implementation target changes its dependencies. This becomes an issue if such coupling happens to an external dep implementation.

Repro: https://github.com/wix-playground/scala-unused-deps/tree/master/type_annotations

a.Hello depends on b.LoggingProvider, but it also asks to add //type_annotation/c, which is implementation detail of b.LoggingProvider.

If implementation of LoggingProvider is changed to use d.BetterLogger, it requires not only to add d to b, but also d to a, and remove c from a.

liucijus avatar May 28 '20 08:05 liucijus

One way to address this problem is to export c on b

liucijus avatar May 28 '20 09:05 liucijus

Have not actually tested to be for sure but I think the reason you need to add the dependency is because you are calling log on a type of c.Logger, so in fact a's source code does use c directly. If however on b it was declared as val logger: LoggerInterface = c.Logger(), (where LoggerInterface is declared in some package that's neither c nor d), then I think a wouldn't have to depend on c or d.

@ittaiz is this behavior what we want? (it seems reasonable to me personally but not sure if people agree with that).

Jamie5 avatar May 28 '20 16:05 Jamie5

@liucijus did not quite see the relation to https://github.com/bazelbuild/rules_scala/issues/867#issuecomment-588516930 as you mentioned in the other issue.

Jamie5 avatar May 28 '20 16:05 Jamie5

@Jamie5 just want to say that we may need more complex heuristic to decide where the dep belongs in plus-one mode

liucijus avatar May 28 '20 17:05 liucijus