简体   繁体   English

SBT多模块项目:如何在主模块中提供静态文件(资源)?

[英]SBT multi module project: how to make static files (resources) available in main module?

I develop multi module SBT project. 我开发多模块SBT项目。 In general it's an akka api. 一般来说,它是一个akka api。 It works well, when I run it locally and when I package it in docker. 当我在本地运行它并将其打包在docker中时,它运行良好。

Recently I added a new one module for email templates generation. 最近,我添加了一个用于生成电子邮件模板的新模块。 I decided to use scalate mustache for this purpose. 我决定为此使用鳞状胡须 For a testing reason I created a simple template hello.mustache in email/src/main/resources/templates . 出于测试原因,我在email/src/main/resources/templates创建了一个简单的模板hello.mustache

Then I run code which uses the template from the class located in email/src/main/scala . 然后,我运行代码,该代码使用位于email/src/main/scala的类中的模板。 Everything compiled ok (scalate templates & scala code). 一切都编译正常(缩放模板和Scala代码)。

After I add a dependency to the email module to the security module which is included in app module: 在将对电子邮件模块的依赖项添加到应用程序模块中包含的安全模块后:

import sbt.Keys._
import NativePackagerHelper._

lazy val core = project.in(file("core"))
  .settings(name := "core")
  .settings(Common.settings)
  .settings(libraryDependencies ++= Dependencies.commonDependencies)
  .enablePlugins(JavaAppPackaging)

lazy val email = project.in(file("email"))
  .settings(name := "email")
  .settings(Common.settings)
  .settings(libraryDependencies ++= Dependencies.emailDependencies)
  .enablePlugins(JavaAppPackaging)

lazy val contacts = project.in(file("contacts"))
  .settings(name := "contacts")
  .settings(Common.settings)
  .dependsOn(core % "test->test;compile->compile")
  .enablePlugins(JavaAppPackaging)

lazy val security = project.in(file("security"))
  .settings(name := "security")
  .settings(Common.settings)
  .dependsOn(email, core % "test->test;compile->compile")
  .enablePlugins(JavaAppPackaging)

lazy val app = project.in(file("."))
  .enablePlugins(JavaAppPackaging, AshScriptPlugin, DockerPlugin)
  .settings(name := "app")
  .settings(Common.settings)
  .dependsOn(core, security, contacts)
  .settings(
    mainClass in Compile := Some("com.app.Main"),
    packageName in Docker := "app-backend",
    version in Docker := "latest",
    dockerBaseImage := "openjdk:8-jre-alpine",
    dockerExposedPorts := Seq(5000)
  )

I see the following errors, while trying to run the email code: 尝试运行电子邮件代码时,我看到以下错误:

Exception in thread "main" org.fusesource.scalate.TemplateException: scala.tools.nsc.symtab.classfile.ClassfileParser$unpickler$.unpickle([BILscala/reflect/internal/Symbols$Symbol;Lscala/reflect/internal/Symbols$Symbol;Ljava/lang/String;)V
    at org.fusesource.scalate.TemplateEngine.compileAndLoad(TemplateEngine.scala:886)
    at org.fusesource.scalate.TemplateEngine.compileAndLoadEntry(TemplateEngine.scala:745)
...

How to make email module code work in another modules? 如何使电子邮件模块代码在其他模块中工作?

Additional info: I try to run the code directly from IDE by run of the Main class from the app module. 附加信息:我尝试通过从app模块运行Main类直接从IDE运行代码。 Scala version 2.12.2; Scala 2.12.2版本; Scalate version 1.8.0; 标定版本1.8.0; sbt version 0.13.8; sbt版本0.13.8;

I'm afraid that you encountered a bin compatibility issues among several scala compiler versions. 恐怕您在多个Scala编译器版本之间遇到了bin兼容性问题。 Explicitly overriding the scala lang version like this is preferred to avoid such problems. 最好像这样显式覆盖scala lang版本,以避免出现此类问题。

dependencyOverrides := Set(
  "org.scala-lang"         % "scala-library"             % scalaVersion.value,
  "org.scala-lang"         % "scala-reflect"             % scalaVersion.value,
  "org.scala-lang"         % "scala-compiler"            % scalaVersion.value
),

In my particular case there was a problem in a conflict of log4j version of scalate and one other scala lib. 在我的特定情况下,存在一个问题,即scalate的log4j版本与另一个scala lib冲突。 So the solution which works for me is: 所以适合我的解决方案是:

"org.scalatra.scalate"    %% "scalate-core" % "1.8.0" excludeAll(ExclusionRule(organization = "org.slf4j"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM