I have package structure similar to below;
myapplication/
├── my-library/
│ └── src
│ └──main
│ └── scala
│
├── my-other-library/
│ └── src/
│ └──main/
│ └── scala/
│── my-executable-project/
│ │── src/
│ │ └──main/
│ │ └── scala/
│ └── resources/
│ └── somefile.txt
└── build.sbt
When I run the tests via sbt
or intellij;
- relative files (e.g.
new File("build.sbt")
) being relative tomyapplication
.
When I run the project with reStart
via sbt-revolver or from the binary;
my-executable-project
is being the working directory. So to access samebuild.sbt
file I should be usingnew File("../build.sbt")
This project structure make sense to me because there may be other executable projects later. I prefer keeping every project under the parent one.
Only my-executable-project
is being packaged and run in the production. And when it runs there again my-executable-project
is being the working directory.
The only inconvenience right now is when I want to reference to a relative file it is different in tests and regular runs.
I overcome resource loading with the usage of classpath and classloader but couldn't find a way for relative file references. When app runs tests fail, when tests run app fails.
Edit: This is how my one and only build.sbt looks like;
lazy val root = project
.in(file("."))
.disablePlugins(RevolverPlugin)
.aggregate(library1, library2, service, common)
.settings(
settings,
name := "parent",
version := "0.1"
)
lazy val common = project
.in(file("common"))
.disablePlugins(RevolverPlugin)
.settings(
settings,
name := "common",
libraryDependencies ++= ... some deps ...
)
lazy val library1 = project
.in(file("library1"))
.disablePlugins(RevolverPlugin)
.dependsOn(common)
.settings(
settings,
name := "library1",
libraryDependencies ++= ... some deps ...
)
lazy val library2 = project
.in(file("library2"))
.disablePlugins(RevolverPlugin)
.dependsOn(common)
.settings(
settings,
name := "library2",
libraryDependencies ++= ... some deps ...
)
lazy val service = project
.in(file("service1"))
.dependsOn(library1, library2)
.enablePlugins(JavaServerAppPackaging)
.settings(
settings,
name := "service1",
mappings in Universal ++= directory("service1/src/main/resources"),
mainClass in Compile := Some("my.main.class.service.Main"),
Revolver.enableDebugging(port = 5005, suspend = false),
libraryDependencies ++= ... some deps ...
)