Alexander Mills
Alexander Mills

Reputation: 100010

Maven + Vert.x - "package junit.framework does not exist'

I have the following pom.xml file:

<?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>
    <groupId>cdt</groupId>
    <artifactId>cdt-hive-vertx</artifactId>
    <version>3.4.2</version>
    <packaging>jar</packaging>
    <name>cdt-hive-vertx</name>
    <url>http://maven.apache.org</url>

    <properties>
        <exec.mainClass>cdt.HelloWorldEmbedded</exec.mainClass>
    </properties>

    <dependencies>
        <dependency>
            <groupId>io.vertx</groupId>
            <artifactId>vertx-core</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>

    <build>

        <pluginManagement>
            <plugins>
                <!-- We specify the Maven compiler plugin as we need to set it to Java 1.8 -->
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>

        <!--
        You only need the part below if you want to build your application into a fat executable jar.
        This is a jar that contains all the dependencies required to run it, so you can just run it with
        java -jar
        -->
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <manifestEntries>
                                        <Main-Class>${exec.mainClass}</Main-Class>
                                    </manifestEntries>
                                </transformer>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/services/io.vertx.core.spi.VerticleFactory</resource>
                                </transformer>
                            </transformers>
                            <artifactSet>
                            </artifactSet>
                            <outputFile>${project.build.directory}/${project.artifactId}-${project.version}-fat.jar
                            </outputFile>
                        </configuration>
                    </execution>
                </executions>


            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.4.0</version>
                <executions>
                    <execution>
                        <!-- run the application using the fat jar -->
                        <id>run-app</id>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>java</executable>
                            <arguments>
                                <argument>-jar</argument>
                                <argument>target/${project.artifactId}-${project.version}-fat.jar</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>


    <profiles>
        <profile>
            <id>staging</id>
            <repositories>
                <repository>
                    <id>staging</id>
                    <url>https://oss.sonatype.org/content/repositories/iovertx-3684/</url>
                </repository>
            </repositories>
        </profile>
    </profiles>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.8.2</version>
            </dependency>
        </dependencies>
    </dependencyManagement>


</project>

when I run:

mvn clean package exec:java

I get:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project cdt-hive-vertx: Compilation failure: Compilation failure:
[ERROR] /Users/alexamil/WebstormProjects/nabisco/cdt-hive-vertx/src/test/java/cdt/HelloWorldEmbeddedTest.java:[3,23] package junit.framework does not exist
[ERROR] /Users/alexamil/WebstormProjects/nabisco/cdt-hive-vertx/src/test/java/cdt/HelloWorldEmbeddedTest.java:[4,23] package junit.framework does not exist
[ERROR] /Users/alexamil/WebstormProjects/nabisco/cdt-hive-vertx/src/test/java/cdt/HelloWorldEmbeddedTest.java:[5,23] package junit.framework does not exist
[ERROR] /Users/alexamil/WebstormProjects/nabisco/cdt-hive-vertx/src/test/java/cdt/HelloWorldEmbeddedTest.java:[7,45] cannot find symbol

the error is happening because of the single test case I have:

package cdt;

import junit.framework.Test;   // cannot find these files
import junit.framework.TestCase;
import junit.framework.TestSuite;

public class HelloWorldEmbeddedTest extends TestCase {


}

but I have junit referenced in my pom.xml file in the <dependencyManagement> section.

Anyone know what could be wrong?

Upvotes: 0

Views: 675

Answers (1)

Naman
Naman

Reputation: 31878

Few things over the implementation :-

First, since the module uses the packages from junit, you should include that as well into <dependencies> tag instead of <dependencyManagement> as :

<dependencies>
    <dependency>
        <groupId>io.vertx</groupId>
        <artifactId>vertx-core</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.2</version>
        <scope>test</scope> <!-- this could be just for tests -->
     </dependency>
</dependencies>

Second, Please note though I cannot find the java docs for the specified version of junit artifact but trusting this question seems to me that 4.+ version of the library uses a class @org.junit.Test instead of what you had used in your class i.e. @junit.framework.Test. You might want to change to the latest package name if the version has so in your classes.

Upvotes: 1

Related Questions