How to organize import in a Scala project?

Suppose my project has an org.abc package with several Scala files inside. All Scala files contain the same import statements, for example. import org.x._ , import org.y._ , import org.z._

I do not like the repetition. Is it possible to move all these import statements to a single file?

+5
source share
2 answers

You can use the same template used by scala / package.scala : create an org.abc package object using type and a val for each definition that you want to import from org.{x, y, z}._ :

 package org package object abc { type Maybe[A] = org.x.Maybe[A] val Maybe = org.x.Maybe type MyClass = org.y.MyClass val MyClass = org.y.MyClass } 
+7
source

yes you can using package objects

+1
source

All Articles