0

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>
Raghu
  • 3
  • 3

2 Answers2

0

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).

Fried Hoeben
  • 3,247
  • 16
  • 14
  • I tried removing !pomFile and added jar files location as_!path path/to/location/*.jar_ on the wiki. It is able to find the fixture class but unable to resolve dependency I am using in the fixture **java.lang.NoClassDefFoundError: org.springframework.test.context.TestContextManager**. However, I do not find TestContextManager class in the jar even when I run it locally but it isn't complaining about it in that case. Dummy fixture with no dependencies is working fine. My fitnesse project structure is fitness/src/test/java instead of src/main/java, not sure if that is affecting the behavior. – Raghu Jan 06 '17 at 16:13
  • It sounds like shade plugin is not finding all dependencies (I've had similar problems in the past, caused by the fact that classes were referenced via Spring/xml and not directly causing the shade not to detect them as required dependencies). Maybe the maven dependency plugin (using its copy-dependencies goal) works better for you: that will get all dependencies (not just the used ones) at the cost of a larger docker image. (Using `dependency:copy-dependencies` is also the approach I use in my projects to create a 'standalone' version of a fitnesse installation.) – Fried Hoeben Jan 06 '17 at 16:31
  • That works like a charm. Thanks! I have used `true` with **copy-dependencies** to avoid extra dependencies. – Raghu Jan 06 '17 at 18:28
  • Accept my answer, or your own. To indicate question answered. – Fried Hoeben Jan 06 '17 at 18:59
0

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>
Raghu
  • 3
  • 3