How to organize imports in a Scala project?

import, scala

Solution

You can use the same pattern that is used in scala/package.scala: create an `org.abc` `package object` with a `type` and a `val` for each definitions 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
}

Problem

Suppose my project has package `org.abc` with several Scala files inside. All the Scala files contain the same `import` statements, e.g. `import org.x._`, `import org.y._`, `import org.z._` I don't like the repetition. Can I move all these `import` statements to one single file ?

Original source