Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure IntelliJ to use short package names on "Optimize imports" for a scala codebase?

In a scala project where we are using IntelliJ community edition, we want to use multiple packages per file, so that we can reference them with shorter syntax:

package com.dreamlines.dragonfly
package api
package domain
package harbours

import common.entities.EsHarbour
import common.utils.date.DLDateTime

Yet IntellJ wants to enforce the fully qualified package name and hence on optimizing the imports it changes the code to:

import com.dreamlines.dragonfly.common.entities.EsHarbour
import com.dreamlines.dragonfly.common.utils.date.DLDateTime

How do I configure the behavior of optimize import?

It should

  • at least keep the shortened imports or
  • at best shorten the longer ones automatically

I want to keep the other behavior of optimize import intact, e.g. removing unused imports, adding missing imports, sorting imports. So I don't consider not using optimize imports a valid option.


We are furthermore using the scalafmt formatter, so it may relate to our .scalafmt.conf that looks like this for this project:

version = 2.0.0
style = default
maxColumn = 120
continuationIndent.callSite = 2
continuationIndent.defnSite = 2
align.openParenDefnSite = false
align.openParenCallSite = false
danglingParentheses = true
indentOperator = spray
project.excludeFilters = [".*\\.sbt"]
rewrite.rules = [RedundantBraces, RedundantParens, prefercurlyfors]
unindentTopLevelOperators = true
importSelectors = singleLine
spaces.afterKeywordBeforeParen = true
lineEndings = unix
newlines.penalizeSingleSelectMultiArgList = false
newlines.alwaysBeforeElseAfterCurlyIf = false
binPack.literalArgumentLists = false
runner.optimizer.forceConfigStyleMinArgCount = 1
like image 654
k0pernikus Avatar asked Sep 10 '19 15:09

k0pernikus


1 Answers

It seems that there is a code style option in IntelliJ that forces fully qualified package names. You can disable that and see if that helps: enter image description here

like image 115
Laurynas Lubys Avatar answered Oct 27 '22 00:10

Laurynas Lubys