1
votes

I have the following build.sbt file:

lazy val shared = (project in file("shared")) .
  settings (moduleName := "x-shared") .
  ...

lazy val service = (project in file ("service")) .
  settings (moduleName := "x-api") .
  dependsOn (shared % "compile->compile;test->test", job % "compile->compile;test->test") .
  aggregate (shared, joob) .
  ...

lazy val job = (project in file("job") dependsOn (shared % "compile->compile;test->test")) .
  settings (moduleName := "x-job") .
  ...

The service submodule requires both shared and job modules. The shared project is basically a set of classes used by all the modules. Both job and service are different applications, but we have an endpoint on the service, that requires to start the job application.

The problem is that on runtime, we get the following error when trying to reference the job module classes:

java.lang.NoClassDefFoundError: com/earnest/ingestor/models/Pipeline$

But we are able to reference the shared module without any problem.

The folder structure of the project is the following:

./root
  ./service
  ./shared
  ./job

One thing I notice is that the jar file generated for the job module, does not get copied on the lib folders on the service module, in difference with the shared jar file:

service/target/universal/stage/lib dir contains both:

com.earnest.x-api-localdev.9288.jar
com.earnest.x-shared-localdev.9288.jar

But the job jar gets populated to the jobs module:

job/target/universal/stage/lib contains:

com.earnest.x-job-localdev.9288.jar

I'm pretty new to sbt builds, so not sure if might be missing some piece during the build which is done via the sbt clean command. We are using the sbt-native-package plugin. I'm not sure what other information might be useful to share so I extracted the build.sbt key points, thanks for the help in advance.

sbt plugins:

addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.11")

Update 1

The application is being launch from a launcher.jar using what it seems to be the LauncherJarPlugin from the build.sbt file. One thing I've notice is that the launcher.jar does not contain the com.earnest.x-job-localdev.9288.jar in the ClassPath on META_INF/MANIFEST.MF

1
Which build command did you use? sbt-native-packager is usually not used to produce an uberjar. For that sbt-assembly is normally used. - Mateusz Kubuszok
I'm using the sbt clean <module> command, not sure how is it configure but this command is building the complete project. Another thing I've notice is that the application is run via a launcher.jar, I see we are using the LauncherJarPlugin in the build.sbt as well, which if extracted using thejar xf command, the META_INF/MANIFEST.MF does not include com.earnest.x-job-localdev.9288.jar in the classpath. - user1129209
Without details about configuration I doubt we will be able to figure this out. - Mateusz Kubuszok
Should I share just the complete build.sbt file? I just do not wanted to copy paste that whole block. - user1129209
Copy paste anything related to building logic. - Mateusz Kubuszok

1 Answers

0
votes

I was able to resolve my issue with setting up the service module adding job % "compile->compile;test->test"

The whole block looks like:

lazy val service = (project in file ("service")) .
  settings (moduleName := "x-api") .
  dependsOn (shared % "compile->compile;test->test", job % "compile->compile;runtime->runtime;test->test") .
  aggregate (shared, job) .
  ...