Cherry
Cherry

Reputation: 33534

How run Embedded mysql server via maven?

Is there a way to run some lightweight MySql during maven integration tests? All I have found is libmysqld, but it seems to be launched inside client application. May be there is a way or wrapper to run it as litle server? Or other ways/implementation to run lightweight Mysql server?

Note

There is also mysql-je library, looks good but too old (2006).

Upvotes: 1

Views: 1836

Answers (1)

Hendrik Jander
Hendrik Jander

Reputation: 5715

As @hotzst mentioned, an embedded database like h2 or hsqldb would be already very helpful.

But if you really have to , you could use the https://github.com/rhuss/docker-maven-plugin to start any piece of software within your maven build process.

The only precondition would be a working docker or docker-machine installation on your machine.

I use the following code snippet to start a mongodb while doing integration test

<plugin>

    <groupId>org.jolokia</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>0.13.7</version>

    <configuration>                                 
        <logDate>default</logDate>
        <autoPull>true</autoPull>
        <images>
            <image>
                <alias>mysql</alias>
                <name>mysql:5.7.10</name>
                <run>
                    <ports>
                        <port>3306:3306</port>
                    </ports>
                    <log>
                        <prefix>Mongo</prefix>
                        <color>yellow</color>
                    </log>
                </run>
            </image>
        </images>
    </configuration>

    <executions>
        <execution>
            <id>start</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>build</goal>
                <goal>start</goal>
            </goals>
        </execution>
        <execution>
            <id>stop</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>stop</goal>
            </goals>
        </execution>

    </executions>
</plugin>

you can start the all integration tests and the according maven phases with mvn:verify. The first time you run this plugin may take a while.

Upvotes: 2

Related Questions