Fitnesse error when used with spotify maven plugin and docker

321 views Asked by At

I am using spotify maven plugin to create a fitnesse docker image and run it on a container. I am able to bring the fitnesse up and run the tests successfully locally without using spotify maven plugin and docker but not when I use those. I get the following error when I start the fitnesse Error message

Here is the contents of FrontPage fitnesse wiki which generally generally takes care of resolving dependencies as per http://blog.xebia.com/fitnesse-and-dependency-management-with-maven/

!contents

!define TEST_SYSTEM {slim} !pomFile pom.xml

!note Release ${FITNESSE_VERSION}

Here is the contents of my pom.xml:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>

                        <shadeTestJar>true</shadeTestJar>
                        <transformers>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>fitnesseMain.FitNesseMain</mainClass>
                            </transformer>
                        </transformers>                         
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>com.spotify</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <configuration>
                <baseImage>${docker.registry.host.slash}mcpi/service</baseImage>
                <entryPoint>["java","-jar","${serviceBin}/${finalJarName}.jar","-p","8000"]</entryPoint>
                <imageName>mcpi/${project.name}</imageName>
                <runs>
                    <run>mkdir -p ${serviceHome}</run>
                </runs>
                <workdir>${serviceHome}</workdir>
                <resources>
                    <resource>
                        <targetPath>${serviceHome}</targetPath>
                        <directory>${basedir}/src/test/resources</directory>
                    </resource>
                    <resource>
                        <targetPath>${serviceBin}</targetPath>
                        <directory>${basedir}/target</directory>
                        <include>${finalJarName}.jar</include>
                    </resource>
                    <resource>
                        <targetPath>${serviceBin}</targetPath>
                        <directory>${basedir}/target</directory>
                        <include>${finalTestJarName}.jar</include>
                    </resource>
                    <resource>
                        <targetPath>${serviceBin}</targetPath>
                        <directory>${basedir}</directory>
                        <include>pom.xml</include>
                    </resource>
                </resources>
            </configuration>
        </plugin>
2

There are 2 answers

4
Fried Hoeben On BEST ANSWER

I believe your problem might be that you don't include your maven settings and repository in the docker image, so the !pomFile does not work inside your docker image.

Having said that: you probably don't need it, since you bundle all your classes and dependencies (at least I assume that what the 'shade plugin' does for you). So you can probably disable the 'maven class path plugin, to prevent the problem you experience now. Disabling the maven classpath plugin can be done by adding -Dfitnesse.wikitext.widgets.MavenClasspathSymbolType.Disable=true to your Java command line starting FitNesse in docker (or by removing the line from the wiki page of course, but that impacts how you work locally).

But I don't know whether your tests will work immediately, or that you have to do something extra to ensure the generated 'final jar' is on the class path of the Java process that is started once an actual test is started (but you can try that locally by running with the !pomFile removed and starting from the jar created by the shade plugin).

0
Raghu On

Fitnesse was unable to parse pom.xml as maven is not set up in docker. Instead of !pomFile pom.xml in my fitnesse wiki, I used !path path/to/jars/*.jar.

Though above error was gone, maven-shade-plugin could not resolve all the dependencies like spring-test.

I had to add maven-dependency-plugin to pom.xml so that all the dependencies are resolved <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${basedir}/target/dependencies</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>false</overWriteSnapshots> <overWriteIfNewer>true</overWriteIfNewer> <excludeTransitive>true</excludeTransitive> </configuration> </execution> </executions> </plugin>

and moved those to docker using spotify docker-maven-plugin

<plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <configuration>
                    <baseImage>${docker.registry.host.slash}service</baseImage>
                    <entryPoint>["java","-jar","${serviceBin}/${finalJarName}.jar","-p","8000"]</entryPoint>
                    <imageName>mcpi/${project.name}</imageName>
                    <runs>
                        <run>mkdir -p ${serviceHome}</run>
                    </runs>
                    <workdir>${serviceHome}</workdir>
                    <resources>
                        <resource>
                            <targetPath>${serviceHome}</targetPath>
                            <directory>${basedir}/src/test/resources</directory>
                        </resource>
                        <resource>
                            <targetPath>${serviceBin}</targetPath>
                            <directory>${basedir}/target</directory>
                            <include>${finalJarName}.jar</include>
                        </resource>
                        <resource>
                            <targetPath>${serviceBin}</targetPath>
                            <directory>${basedir}/target</directory>
                            <include>${finalTestJarName}.jar</include>
                        </resource>

                        <resource>
                            <targetPath>${serviceBin}</targetPath>
                            <directory>${basedir}/target/dependencies</directory>
                        </resource>
                    </resources>
                </configuration>
            </plugin>