'SAST job fails + GitLab + Spring boot + Maven

I have a multi-module maven Spring Boot project. During the Test pipeline stage, I get the below error.

 The specified user settings file does not exist: /builds/teams/systems/service/app/modals/.m2/ci_settings.xml

The project app has two modules -> service & modals. The project root has a .m2 folder within which lies the settings.xml file.

I have included the common.gitlab-ci.yml which has the SAST template included. The issue is that the spotbug-sast job fails and complains that the service module does not have a .m2/settings.xml file. To test, I tried creating a file at the same path in service module which worked but failed to build modals. The same may also work with modals as well if I create the settings.xml file within modals.

Here is the (partial) gitlab-ci yaml:

 variables:
   MAVEN_CLI_OPTS: -s .m2/ci_settings.xml --batch-mode
   MAVEN_OPTS: -Dmaven.repo.local=.m2/repository
 
 
 stages:
   - compile
   - test
    
 include:
   - project: '/gitlab/'
     ref: master
     file: '/security/common.gitlab-ci.yml'
   
 compile:
   image: maven:3.6.3-jdk-8-slim
   stage: compile
   script:
     - mvn $MAVEN_CLI_OPTS clean compile $MAVEN_OPTS
   only:
     - merge_requests
     - web
     
 test:
   image: maven:3.6.3-jdk-8-slim
   stage: test
   script:
     - mvn $MAVEN_CLI_OPTS verify $MAVEN_OPTS
   only:
     - merge_requests
     - web

Everything worked perfectly before adding this SAST template. I am not sure if it is correct to create the settings.xml file inside all the modules.

How can I get rid of this error? Please help to understand how this works.



Solution 1:[1]

I had the same problem and could solve it by making the Maven settings path absolute. In your example this would be:

variables:
  MAVEN_CLI_OPTS: -s $CI_PROJECT_DIR/.m2/ci_settings.xml --batch-mode

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Roland