Some projects need a priming build - mostly to load the deps, otherwise the tests would fail when looking for it.

While it's typically an error of the tests or a wrong build order / dependencies, sometimes the project is kept such as it's not a biggest issue.

 

Here's how to determine if such priming build is needed.

Basically, you pick one artifact and check for it's existence in local repository.

mvn dependency:get -o -Dartifact=G:A:V

The trick is to feed it the right version.

Well, provided you run this in project's directory, you can use ${project.version}.

 

mvn dependency:get -o -Dartifact=org.jboss.windup.graph:windup-graph:\${project.version}

 

This will return 0 code when it exists, 1 code if it does not.

 

In our project, I needed to polish this in to a build script. So here's my result:

 

##  Determine this script's location ("Tools" home dir).
scriptPath="$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0##*/}")"
# For the case when called through a symlink
scriptPath=`readlink -f "$scriptPath"`
scriptDir=`dirname $scriptPath`

SETTINGS="-s $scriptDir/settings.xml"

localRepo=""
for val in "$@"
do
    echo $val
    if [[ "$val" == -Dmaven.repo.local=* ]] ; then localRepo=$val; fi
done

## Priming build to avoid WINDUP-322
if ! mvn $SETTINGS $localRepo dependency:get -o -Dartifact=org.jboss.windup.graph:windup-graph:\${project.version} > /dev/null
then
    echo -e "\n\nRunning a priming build...\n\n"
    mvn $SETTINGS $localRepo install -DskipTests
    echo -e "\n\nPriming build finished.\n\n"
fi


set -x
mvn $SETTINGS clean install $localRepo $@

 

Enjoy!