scala multi sbt project:object不是包的成员,找不到类型

时间:2015-08-13 09:09:30

标签: scala sbt

如何从项目abc导入类main以供web配置中项目multi-project sbt中的其他类使用?

sbt compile我得到:
object abc is not a member of package com not found: type abc

虽然从IntelliJ内部编译成功。

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

网络项目中

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 { ..

主项目中

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

可能有什么不对? 感谢。

2 个答案:

答案 0 :(得分:4)

原来,项目main的目录结构不符合maven目录结构,described here

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

Intellij成功编译了该项目,因为无论旧的目录结构是什么,它都在source directory下标记为File -> project structure -> modules -> sources

答案 1 :(得分:0)

由于相似的原因,发生了相同的错误

我有

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

但正确的是

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

./src/main/scala/看起来

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