I have a maven multimodule project of the form

- main
  - storage
     - storage-config
     - storage-utils
     - storage-common
    - tools

I have a class `com.vnera.storage.config.Embedded.java` residing under test
folder in `storage-config` which I want to use in `storage-utils` under
`test` scope. `storage-utils` also needs `storage-config` in main phase.

I have added the below section in `storage-config` pom and I am seeing
`test-jar` of `storage-config` is getting generated.

    <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.4</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>test-jar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

`storage-utils` pom looks like below

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0";
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
        <modelVersion>4.0.0</modelVersion>

        <parent>
            <groupId>com.vnera</groupId>
            <artifactId>storage</artifactId>
            <version>0.001-SNAPSHOT</version>
        </parent>

        <packaging>jar</packaging>
        <artifactId>storage-utils</artifactId>
        <name>utils</name>

        <dependencies>
            <dependency>
                <groupId>com.github.fge</groupId>
                <artifactId>json-patch</artifactId>
                <version>1.9</version>
            </dependency>
            <dependency>
                <groupId>com.vnera</groupId>
                <artifactId>storage-config</artifactId>
                <version>${main.version}</version>
            </dependency>
            <dependency>
                <groupId>com.vnera</groupId>
                <artifactId>storage-config</artifactId>
                <version>${main.version}</version>
                <type>test-jar</type>
                <scope>test</scope>
            </dependency>
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${mvn.surefire.plugin.version}</version>
                    <configuration>
                        <skipTests>true</skipTests>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.apache.maven.surefire</groupId>
                            <artifactId>surefire-junit47</artifactId>

<version>${mvn.surefire.plugin.version}</version>
                        </dependency>
                    </dependencies>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.4</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>test-jar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </project>

My compilation is running fine. But whenever I am trying to access
 `Embedded.java` from a class in `storage-utils` in `test` scope. I am
getting `NoClassDefFoundError` for `Embedded.java`.

Can someone let me know what is going wrong and how can I solve this?

Maven Version - 3.5.3

Reply via email to