Search code examples
mavenansiblejar-with-dependencies

Get jar-with-dependencies using ansible maven_artifact


Is it possible to get a Java jar-with-dependencies using ansible package maven_artifact?

Now for a bit of a context:

  1. I have a simple Java application. This means I need to produce a jar-with-dependencies type of jar for this app to be executable as a stand alone.
  2. I'm pushing my jar using mvn deploy in a registry (in my case: Nexus)
  3. I'm using Ansible to deploy my app and it seems to be a sensible choice to use maven_artifact package (I suppose it manages idempotence better then I would).

Very logically, when I do this, I get the simple jar (without all dependencies) and not the jar-with-dependenices.


Solution

  • You can do this with the following steps:

    • Make sure that your jar-with-dependencies is uploaded to Nexus with a specific classifier, e.g. full. For more info on the classifier, please check the Maven documentation.
    • Use the Ansible maven_artifact module's classifier attribute to point to your full artifact.