简体   繁体   中英

Determine date on Maven profile

As a futher question to this: Fake system clock on certain date

Is it possible to set certain date on Maven profile? After all, I use testing profile which determines the usage of test database.

In your Maven profile, you could pass in a date-time as a system property via Surefire:

...
<profile>
    ...
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <systemPropertyVariables>
                        <testDateTime>2013-01-01T00:00:00.000Z</testDateTime>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
        </plugins>
    </build>
</profile>
...

And then use it in your tests like so:

final String dateTime = System.getProperty("testDateTime");
// parse date-time etc...

Does that help?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM