For comments, Use this tweeter post

Coursier is not only an artifact fetch tool and library, it can also be used to start a service or an application (JVM based) in quite an efficient way, by just downloading the minimal set of the required files while reusing those which have already been downloaded and cached on your host, or on a shared space.

Consider this simple application web-echo which implements a simple REST API, the size of the published 1.0.0 artifact on maven-central is only 118KB, it is small because its required dependencies just need to be declared instead of being provided.

Let’s put everything in perspective for web-echo 1.0.0 :

  • 118 KB if published on maven central as a “library”
  • 29685 KB if published somewhere using a classic packaging
    • this is because of all its required dependencies which are part of the packaging

This is a 25000% size tax on each deployment for a legacy packaging.

When first started coursier will of course download everything :

cs launch fr.janalyse::web-echo:1.0.0

(Execute curl http://localhost:8080/info to get a response.)

But for all others deployments where only the code has been changed, it will just download the main artifact, and for a small bug release fix it will still be less than 120KB.

Try it with web-echo 1.0.1 :

cs launch fr.janalyse::web-echo:1.0.1

(just 119K have been downloaded and this web service starts in ~800ms)

So using such approach to integrate or deploy something will save you a lot of space and network bandwidth while making your CI/CD pipelines quite faster.

I’m more and more convinced that using dedicated docker image for a service or an application is not a good idea because of all the overhead it implies. Instead using a generic or custom-made coursier docker image, with a good management of the cached artifacts file system will bring a lot of advantages.

In fact using such approach allows you to decouple the code artifact from how it is executed, in fact just describe how to run it instead of provide everything to execute it. In the case of web-echo, this is quite simple, the binary artifact already contains a META-INF/MANIFEST.MF which give the code main entry point, and maven central knows its dependencies as well as it can provide them for coursier.

Through coursier launch options and environment variables you have everything needed to customize your application as you wish :

export WEB_ECHO_PREFIX=truc
cs launch --java-opt -Xms50m --java-opt -Xmx50m fr.janalyse::web-echo:1.0.1 

Test it using : curl

That’s all Folks.

For comments, Use this tweeter post

Some other related topic links :