Alex
Alex

Reputation: 12019

scala multi sbt project: object is not a member of package, not found type

How do I import class abc from project main to be used by another class in project web in a multi-project sbt configuration?

Upon sbt compile I get:
object abc is not a member of package com not found: type abc

While compilation from within IntelliJ is successful.

build.sbt

lazy val main = project.in(file("main"))
  .settings(commonSettings: _*)

lazy val web = project.in(file("web"))
  .settings(commonSettings: _*)
  .enablePlugins(PlayScala)
  .dependsOn(main)

lazy val root = (project in file("."))
  .dependsOn(web, main)
  .aggregate(web, main)
  .settings(commonSettings: _*)


mainClass in root in Compile := (mainClass in web in Compile).value

fullClasspath in web in Runtime ++= (fullClasspath in main in Runtime).value

fullClasspath in root in Runtime ++= (fullClasspath in web in Runtime).value

Inside web project:

package com.company.web.controllers
import _root_.com.company.main.abc // also tried without root. 
// Intellij recognizes the import successuflly

class Posts @Inject() (repo : abc) extends Controller { ..

Inside main project:

package com.company.main
class abc @Inject() (){

What could be wrong? Thanks.

Upvotes: 6

Views: 6543

Answers (2)

milahu
milahu

Reputation: 3529

had the same error, for a similar reason

i had

lazy val Project_1 =
  Project(
    id = "project-1",
    base = file("./project-1/"),
  )
  .settings(
    sourceDirectory := file("./src/main/scala/"),
  )

but correct is

  .settings(
    sourceDirectory := file("./src/"),
  )

./src/main/scala/ looks like

$ tree src/main/scala/
src/main/scala/
└── org.myorganization.myname
    └── myproject
        ├── MySource1.scala
        └── MySource1.scala

Upvotes: 0

Alex
Alex

Reputation: 12019

Turned out the directory structure of project main wasn't according to maven directory structure, as described here

src/
  main/
    scala/
       com/bla/bla
  test/
    scala/
       <test Scala sources

Intellij was successfully compiling the project because whatever old directory structure was in place, it was marked as source directory under File -> project structure -> modules -> sources

Upvotes: 4

Related Questions