wulfgarpro
wulfgarpro

Reputation: 6934

Maven phase/goal precedence issue

I have some properties in two bash scripts I want substituted when running mvn test, such that one script might be executed before the test phase, and one after, using the exec-maven-plugin.

The bash scripts look like so:

startMongo

#!/bin/bash

${mongodNixDirLocation}/mongod --fork --logpath "${mongodLogDir}" --port ${mongodbTestPort}

/bin/sleep 10

stopMongo

#!/bin/bash

mongoDbServer=`lsof -i tcp:${mongodbTestPort}| awk 'NR!=1 {print $2}'`

for i in $mongoDbServer; do
    echo "Stopping mongo DB server instance: $i"
    kill -s SIGINT $i
done

I seem to be having issues with the order of execution when I run mvn test. The output is like so.

The exec-maven-plugin is trying to execute the startMongo script before the proper substitutions have been made - hence the error message appearing to execute mongod from /mongod.

If I run mvn process-test-resources, the substitutions are correctly made, and I can manually run the script successfully.

My pom.xml is configured like so. How can I appropriately configure the correct phases such that this will work?

Upvotes: 0

Views: 165

Answers (1)

Raghuram
Raghuram

Reputation: 52635

It looks like the problem is in the following line:

<executable>src/test/resources/startMongo</executable>

If this script - startMango - needs filtering, the filtering will be done and the result places in target/test-classes folder. The original file will not be updated.

How about altering the above line as:

<executable>${project.build.directory}/test-classes/startMongo</executable>

Likewise for stopMongo as well.

I am not sure how it manually worked though.

Upvotes: 1

Related Questions