Interested in how you can build a Scala project with dependencies?

sbt package builds a project, but without dependencies, and I can't figure out how to pick them up (I need to get a jar file with all dependencies at the output. If this does not cut out any code that is not used, it will be generally good.

And just as interesting as it can then be deployed in a docker-container.

  • I apologize for not answering for a long time. Regarding the sbt-assembly - I know about him, but he does not want me to build a project. I do everything according to the instructions, as a result says that there are conflicts over dependencies, how to remove them - I have not found it anywhere ( - Anatoliy Evladov
  • based on the fact that you haven’t given an answer to a more general question, it seems to me that it makes sense to ask a new, more specific question: what they tried to do, what error they got (see the minimum reproducible example ). - aleksandr barakin

1 answer 1

I use sbt-native-packager to pack an application with dependencies. There is a stage task that packages all the packages in target / universal / stage / libs and creates a bash file in / target / universal / stage / bin to run

In order to deploy in the docker, I create a dockerfile in the project repository. To create an image, I use scripts that copy the assembled application and dockerfile into one folder. In the dockerfile it turns out something like:

FROM kondaurov/jre ADD app /app ENTRYPOINT ["bin/bash", "/app/bin/myapp"] 

Next, I make this folder in tar.gz and upload it to nexus so that you can download the release from anywhere

to create an image just run:

 docker build -t myApp . 
  • Thank you very much, be sure to try your option. And by nexus - as I understand it, it is not necessary if I use the docker registry?) - Anatoliy Evladov
  • I use nexus as a remote file storage, yes, it is optional. Everyone is looking for a convenient option for themselves. - Alexander Kondaurov
  • I didn’t manage to set up my own docker-registry, I’m supposed to mess up with ssl certificates, https, and so on. It's easier for me to download and collect the image in the docker myself already. Maybe there is a simpler way, but for the time being I stopped at this option - Alexander Kondaurov
  • Hmm ... but do not tell me how to configure the nexus so that the rock project used it as a proxy? I understand that you use it that way except for just file storage? I just kind of hooked it up - but in fact the files don’t go through it ( - Anatoliy Evladov
  • I do not publish artifacts there, I just store ready binaries. As a proxy, it works for npm and bower packages - Alexander Kondaurov