Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

scala

sbt

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.

like image 428
Alex Avatar asked Aug 13 '15 09:08

Alex


1 Answers

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

like image 73
Alex Avatar answered Oct 12 '22 04:10

Alex