53

I get the following warning whenever I start my Scala application:

WARN - imported `SVNProperties' is permanently hidden by definition of object SVNProperties in package core, at line 4 of app/core/SVNResource.scala

What could this mean?

trajectory
  • 1,499
  • 3
  • 16
  • 21
  • 1
    Do you get this when you run the app or when you compile it? Is it scala or scalac that's issuing this warning? – sblundy Feb 11 '11 at 16:22

11 Answers11

48

You probably have code that looks something like this:

object Hidden {
  import scala.collection.immutable
  object immutable { def x = 7 }
}

except in a less obvious way. You're importing something--in my example, the package immutable--and then you go and define something else with the same name that prevents you from using what you imported.

In particular, it looks like you tried to import SVNProperties into SVNResource.scala, except that SVNResource.scala defines its own SVNProperties which hides the import.

Rex Kerr
  • 166,841
  • 26
  • 322
  • 407
  • 39
    Another common cause is that `SVNProperties` is in the same package and so is already in scope. Trying to import it explicitly results in this warning. – Nick Nov 25 '11 at 14:41
  • In 2.13, if the definition is in a different file, the import correctly works. With nested packages, that definition might not be in the same package, but in some enclosing package, in which case it's obvious that my "local" import should just work as intended. If the import imports that definition which would have been visible anyway (for example, it's in the same package), the import also just works and there is no warning either. – som-snytt May 29 '19 at 20:45
37

I encountered this warning after moving some classes from one package to another. I guess there was some conflict between the new location and binaries from the old location. In my case this helped:

sbt clean
astasiak
  • 790
  • 1
  • 6
  • 13
14

I got this warning when my class was importing classes in the same package.

Once I removed the unnecessary import, the warnings were removed.

Todd
  • 2,824
  • 2
  • 29
  • 39
Nikhil Kumar K
  • 1,089
  • 10
  • 13
4

If the warning comes from importing a class with the same name, you can always use import renaming.

package domain

case class Company (...

package models

import domain.{Company => _Company}

object Company extends SkinnyCRUDMapper[_Company] {
Pere Barceló
  • 364
  • 2
  • 3
2

This happened to me after moving a class from one package to another, like in astasiak's case. I ran sbt clean with no luck. For the life of me, I couldn't find the class in the old location.

However, I had other errors preventing me from building. When I fixed those, this error disappeared. My guess is that until you can build cleanly, sbt still thinks you have the class is in the old package, and includes this error with any other build errors that are preventing you from building.

My advice? Check for other compilation errors and fix those -- you might be erroneously getting this error due to sbt having an outdated view of your package structure since its last successful build.

Aphex
  • 7,390
  • 5
  • 33
  • 54
1

Just to further expand on a comment posted by Nick, as this was the case for me:

Another common cause is that SVNProperties is in the same package and so is already in scope. Trying to import it explicitly results in this warning.

More concretely, you may have:

package app.core

// No need to import the following - it is already visible as 
// you are in the same package
import app.core.SVNProperties

object SVNResource {

Use instead:

package app.core

object SVNResource {

(Opinion) As a matter of coding style you may want to camel case your variables differently like for eg. SvnProperties, SvnResource. It reads easier for most people, see also this question.

user1485864
  • 499
  • 6
  • 18
0

I had a main class with name Server and I was creating a jetty server in the main class in the following way.

 import org.eclipse.jetty.server.Server

 var server:Server=new Server()

I got the below warn on running sbt run

 > [warn] /home/xxx/xxx/xxx/src/main/scala/com/xxx/xxx/main/Server.scala:3:

> imported `Server' is permanently hidden by definition of object Server in package main
    [warn] import org.eclipse.jetty.server.Server
    [warn]                                 ^
    [warn] one warning found

I renamed my main class and the warning disappeared.

saurav.varma
  • 280
  • 2
  • 10
0

If you are using Scala Eclipse IDE you can do :

Project > Clean...

After that all the warning will be removed.

esinik
  • 49
  • 2
0

Also, make sure the name of the package you import =/= object name.

Chalikov
  • 143
  • 1
  • 10
0

I got this by having circular dependencies. Both my classes were using each other on accident.

RyanQuey
  • 705
  • 1
  • 9
  • 29
-1

Issue is related to dependency conflict, When you have same class in multiple Jars compiler found one of class is hidden and gives an error.

check for your Jar version is same across project or try to change name/package for one of conflicted class