sbt / sbt-assembly

Deploy über-JARs. Restart processes. (port of codahale/assembly-sbt)
MIT License
1.95k stars 224 forks source link

Classes from other projects/Modules not being included #440

Closed kevomacartney closed 3 years ago

kevomacartney commented 3 years ago

I have created a project with multiple modules, and I have noticed that the jar does not include classes from some projects. Please see the demo repo: https://github.com/kelvinmac/assembly-test

We have two projects: app which has a class Main and project globalApp which is the root project and aggregates the app project. When we assemble the jar by running assembly task in sbt, I find that the class under project app isn't being included in the final jar which results to:

Error: Could not find or load main class com.kelvin.assembly.Main
Caused by: java.lang.ClassNotFoundException: com.kelvin.assembly.Main

I have inspected the jar too see the classes in the jar and can confirm that the class isn't there.

eed3si9n commented 3 years ago

Thanks for creating a repro project.

  .aggregate(app)

is just for command broadcasting. In other words this turns typing assembly into globalApp/assembly and app/assembly. To create dependency between the subprojects what you need is

  .dependsOn(app)

https://www.scala-sbt.org/1.x/docs/Multi-Project.html#Classpath+dependencies

kevomacartney commented 3 years ago

@eed3si9n Thanks for the quick response. I've noticed that when I change it to dependsOn it does work, however only dependancies in the root project are included in the final assembly. That is, if dependancy a is included in globalApp and dependancy b is include in app only dependancy b is include in the final Jar. How do I tell sbt-assembly to include dependancies from all sub projects? I've updated the repo to reflect the issue.