Skip to content

Instantly share code, notes, and snippets.

@ksylvan
Created March 24, 2017 21:20
Show Gist options
  • Save ksylvan/33e0f4c7486e04df897d713908fe11d3 to your computer and use it in GitHub Desktop.
Save ksylvan/33e0f4c7486e04df897d713908fe11d3 to your computer and use it in GitHub Desktop.
Hack Maven's ~/.m2/settings.xml to add a new profile and its properties.
# MVN IDEA settings
#
---
- hosts: all
gather_facts: false
roles:
- cmprescott.xml
vars:
- m2_settings_file: ~/.m2/settings.xml
tasks:
- name: Make sure ~/.m2 exists
file: path=~/.m2 state=directory mode=0755
- name: Does {{ m2_settings_file }} exist?
stat: path={{ m2_settings_file }}
register: m2_settings
- block:
- debug:
msg: 'WARNING: No {{ m2_settings_file }} exists.'
- debug:
msg: Generate one and try again.
when: not m2_settings.stat.exists
- block:
- name: See if mvnidea profile already there
xml:
file: "{{ m2_settings_file }}"
namespaces:
mvn: http://maven.apache.org/SETTINGS/1.1.0
xpath: /mvn:settings/mvn:profiles/mvn:profile[mvn:id = "mvnidea"]
count: true
register: mvnidea_profile_id
- block:
- name: Add child profile
xml:
pretty_print: true
file: "{{ m2_settings_file }}"
xpath: /mvn:settings/mvn:profiles
namespaces:
mvn: http://maven.apache.org/SETTINGS/1.1.0
add_children:
- profile: ''
- name: Make this an "mvnidea" profile
xml:
pretty_print: true
file: "{{ m2_settings_file }}"
xpath: /mvn:settings/mvn:profiles/mvn:profile[last()]
namespaces:
mvn: http://maven.apache.org/SETTINGS/1.1.0
add_children:
- id: 'mvnidea'
- properties: ''
- name: Set up "mvnidea" profile properties
xml:
pretty_print: true
file: "{{ m2_settings_file }}"
xpath: /mvn:settings/mvn:profiles/mvn:profile[mvn:id = "mvnidea"]/mvn:properties
namespaces:
mvn: http://maven.apache.org/SETTINGS/1.1.0
add_children:
- 'mvnidea.compiler.noWarn': 'true'
- 'mvnidea.compiler.deprecation': 'false'
- 'mvnidea.compiler.parallel': 'true'
- 'mvnidea.compiler.heapSizeMb': '4096'
- 'mvnidea.maven.importAutomatically': 'false'
- 'mvnidea.maven.updateMavenHome': 'true'
when: mvnidea_profile_id.count == 0
when: m2_settings.stat.exists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment