Try changing the oder, java.lang first then scala then scala.Predef
Hey, thanks, that worked! But thatâs just the start. It replicates the default imports, but I am still having a problem with adding my own custom âPredefâ. I tried this little test:
scalacOptions += â-Yimports:java.lang,scala,scala.Predef,myPackage.test1â
where âmyPackage.test1â exists. And here is the result:
[error] error: bad preamble import myPackage.test1
What am I missing?
If youâre adding your own (the one that you defined) objects/packages etc they need to live in a separate build unit. This could either be another sub-project in sbt or if youâre building a library and always want to import it, you could also publish it as a jar and depend on it in the binary way (as opposed to source code). No matter what you do you canât autoimport things in the same build.
Thanks. Would it be possible for the error message to provide a clue? Or perhaps a reference to a detailed documentation page on -Yimports?
Donât know. Iâm not part of the compiler and/or Scala team. Just some guy on the internetâŚ
Yes, but a very useful guy on the InternetâŚ
Iâm glad to have discovered this feature. There are a couple of functions from my teaching library that I use all the time, and which reuse standard names from Predef
. If I forget a manual import, I end up using the default functions instead, a mistake I may not catch at compile-time. Using -Yimports
is now making my life easier.