2

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.

avi.elkharrat
  • 6,100
  • 6
  • 41
  • 47
  • 1
    Are you pushing the _jar-with-dependencies_ to Nexus? If so, you could probably download it using the `classifier` parameter of the `maven_artifact` module: https://docs.ansible.com/ansible/2.6/modules/maven_artifact_module.html – nwinkler Nov 27 '18 at 10:10
  • Nice call. I'm checking it. – avi.elkharrat Nov 27 '18 at 11:07
  • BTW, documentation is absolutely NOT explicit on what a classifier is: "classifier: The maven classifier coordinate" – avi.elkharrat Nov 27 '18 at 11:09
  • 1
    Agreed, there's very little info there. More info on the classifier here: https://maven.apache.org/pom.html#Dependencies – nwinkler Nov 27 '18 at 11:18
  • 1
    IT WORKED AWESOME! Willing to give you full credit for this. Please post an answer so I can vote you up and flag as correct answer. – avi.elkharrat Nov 27 '18 at 11:30
  • Answer posted - happy that I could be of help! – nwinkler Nov 27 '18 at 11:33
  • 1
    Agreed. I should have known better and guess that the classifier is a native maven property! Thx so much for your help! – avi.elkharrat Nov 27 '18 at 11:34

2 Answers2

3

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.
nwinkler
  • 52,665
  • 21
  • 154
  • 168
  • 1
    I actually didn't even bother renaming it as `full`. `classifier: jar-with-dependencies` worked awesome. Jar was downloaded and renamed by `maven_artifact` as a normal jar. – avi.elkharrat Nov 27 '18 at 11:38
2

Here's my vamp of the answer:

File organisation should be:

roles/fetch-my-awesome-jar/tasks/main.yml

And content:

---
- name: fetch my awesome jar
  maven_artifact:
    group_id: my.awesome.group.id
    artifact_id: my-awesom-artifact-id
    version: my.awesome.version.number
    classifier: jar-with-dependencies
    extension: jar
    repository_url: http://my-local-nexus:<port>/repository/my-awesome-repo/
    username: my-username
    password: my-password
    dest: my-awesome-target-directory

The version of maven_artifact I'm using has removed the jar-with-dependencies classifier.

avi.elkharrat
  • 6,100
  • 6
  • 41
  • 47