Search code examples
javamavenowner

Aeonbits.OWNER doesn't work in maven? Troubleshooting


For some reason when I run mvn clean test -Denv=test -Dplatform=test maven cannot execute owner's method

private static Environment config = configFactory.create(Environment.class, System.getProperties());

private static String url = config.getUrl();

It just returns nulls instead of fields in .property file

I have several .property files like this: prod.desktop.properties And get their fields with:

@Config.Sources({"classpath:${env}.${platform}.properties"})

I think Build is Success but Test does not run with Maven have almost the same problem. Building works fine and program runs until the certain moment where var supposed to return a property. If instead of, for example, env = config.getEnv() I'll use env = System.getProperty('env') then everything is good.

Full pom.xml

If I run project via IDEA runner (TestNG config) - everything works 100% fine. I have no idea why mvn builder doesn't want to execute ConfigFactory.create() at some point and can't find anyone who have ran maven+owner.

Additional info: If I run config method above but specify -Durl={url} as arg then instead of getting url from the property of Environment.class url be as it's in -Durl. So smh method works but for some reason cannot reach Environment.class...


Solution

  • Okay, I'v localized the problem.

    For some reason mvn cannot read property file adressed like this:

    @Config.Sources({"classpath:${property}.properties"})
    

    So instead you have to change it to:

    @Config.Sources({"file:src/main/resources/${property}.properties"})