Maven Multi module target directory artifact between stages

We have a multi module maven build. The project structure is:

  • all modules are in their own sub directory
  • the parent pom.xml and gitlab-ci.yml in the root directory
  • each module directory has its own pom.xml that inherits the parent pom.xml.

We want to be able to run scan jobs like Sonar, NEXUS IQ, Fortify in their own job during the build stages. The problem is the tools need the compiled code. As a result each job needs to rebuild the project in each stage because the scanners need the /target directory of each module. This means the runner is rebuilding the project for each type of scan. That takes a lot of time and its not the actual code we built for deployment. We want to build, then scan the project we just built, and then deploy if all the scans came back successfully. All of those steps to be different jobs in the pipeline.

Do I need to list out each module’s target directory as an artifact and have it expire within a day? Is there a way to list **/target as an artifact for all modules target directory?