SUMMARY

How can I iteratively run my unit/integration tests in "dev mode" of the liberty-maven-plugin and easily turn on and off the launching of the debugger into the JVM running the tests themselves?

BACKGROUND

While the liberty-maven-plugin by default starts the Open Liberty server in debug mode, sometimes you need to debug into the source of the unit/integration tests themselves. The liberty-maven-plugin dev mode launches the server and will (by default) run my tests each time I hit <Enter>.

I can leverage standard documented approaches, which by default will launch a forked JVM waiting for a debugger on port 5005, e.g.:

mvn -Dmaven.failsafe.debug liberty:dev

But what if I already started dev mode without that property set on the command line?

Is there an easy way to enable the debugger after the fact? Or to toggle it on/off across executions?

1

There are 1 best solutions below

0
On BEST ANSWER

An easy way to "toggle" the debug mode for the tests is to use Maven project properties and dynamically comment/uncomment out the standard test debug properties, e.g. maven.failsafe.debug.

E.g this will launch ITs in a forked JVM, suspended and waiting for the debugger on port 5005:

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.failsafe.debug>true</maven.failsafe.debug>
        <!-- 
          <maven.surefire.debug>true</maven.surefire.debug>
        -->
    </properties>

You can also configure the maven-failsafe-plugin in your pom.xml with normal plugin configuration to configure non-default behavior.

This should work with recent (since v3.1) versions of the liberty-maven-plugin, e.g.:

        <plugin>
            <groupId>io.openliberty.tools</groupId>
            <artifactId>liberty-maven-plugin</artifactId>
            <version>3.3.3</version>
        </plugin>

This could be applied to a simple sample app like the one here: https://openliberty.io/guides/getting-started.html

WARNING

Don't make the mistake of toggling the value to "false" since you're really configuring this parameter. Just comment it out completely to avoid suspending for the debugger.