I have another question: I compile a Scala project...
# general
m
I have another question: I compile a Scala project with
-Wunused:imports
and there are a few cases where I need to put unused imports into the code to make it compile with pants. Is this a bug or do I have to add some extra metadata to help the dependency detection? It happens with classes that are in the same package and thus normally don't need explicit imports.
f
These are failures of the Pants dependency inference. If you are able to isolate the source code context in which the added imports are used , then we can fix the Pants Scala parser to account for them.
Both the source context where the symbol is defined and where it is used.
m
https://gitlab.com/jberkel/digero/-/blob/73381acfc27f31add7e790099fa74ed3197d75c9/core/src/main/scala/digero/ProcessXMLDump.scala The imports in question are on line 3. The classes are used in the pattern matching on lines 22 + 32.
that's all of them
f
Can you open an issue?
m
Sure
h
Instead of adding unused imports in the code to guide dep inference, you can add to
dependencies=[]
in the BUILD file target
So at least the muck is isolated to BUILD files, and doesn't affect the code itself
m
Sorry, I'm struggling a bit. In which BUILD file would this have to go? In the toplevel one, or do I have to create a new one at the level where the dependency is located?
h
Some BUILD file contains a scala_sources() target A whose deps are being incorrectly inferred. So you'd do something like:
Copy code
scala_sources(
  overrides={
    "my_source.scala": { "dependencies": ["path/to/my/missing/dep.scala"]}
  }
)
m
I missed the
overrides
, works now! 👍