如何从项目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() (){
可能有什么不对? 感谢。
答案 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