---
-
  name: "Setting SDKMAN user variables"
  ansible.builtin.set_fact:
    sdk_service_user: "{{ service_user }}"
    sdk_service_group: "{{ service_group }}"

-
  name: "Setting SDKMAN directory"
  ansible.builtin.set_fact:
    sdkman_dir: "{{ service_home_dir }}\\.sdkman"

-
  name: "Installing Maven via SDKMAN"
  ansible.windows.win_shell: |
    C:\tools\msys64\usr\bin\bash.exe -c "source {{ sdkman_dir }}/bin/sdkman-init.sh && sdk install maven {{ maven_version }}"
  register: sdk_install
  changed_when: "'is already installed.' not in sdk_install.stdout"
  failed_when: >-
    sdk_install.rc != 0 and
    'is already installed.' not in sdk_install.stdout

-
  name: "Setting Maven environment variable"
  ansible.windows.win_environment:
    name: MAVEN_HOME
    value: "{{ sdkman_dir }}\\candidates\\maven\\current"
    level: machine

-
  name: "Adding Maven to system PATH"
  ansible.windows.win_path:
    elements:
      - "{{ sdkman_dir }}\\candidates\\maven\\current\\bin"
    scope: machine
    state: present
