Search code examples
javaeclipsemavenm2eclipsem2e

Run maven test with profiles


in Eclipse, i have a MVN project A that depends on mvn project B-C-D

Project B contains a mysettings.xml in wich I have a property like this: <iduser>${my.iduser}</iduser>

I have a maven profile called "deployment" that sets the iduser prop. to "ADMIN". When I launch a maven clean package specifying "deployment" profile, in mysettings.xml I find <iduser>ADMIN</iduser>

I then created a new profile called "mytest" that sets that property to "TESTUSER".

If I call mvn -Dtest=MyClassTest -P mytest on project C, seems like maven does not replace ${my.iduser} in project B mysettings.xml file.

Does anyone know how to get this running in test phase? Thanks


Solution

  • Maven won't do what you're hoping for. The mysettings.xml file will get put into Project B's jar file using whatever profile you specified when you built Project B, and the ${my.iduser} placeholder will be gone (filtered out). It won't come from project B's source directory.

    I've never found a satisfactory way to do this with Maven. If mysettings.xml is a Spring config file, you can use the PropertySourcesPlaceholderConfigurer at runtime, rather than Maven filtering at build time.