繁体   English   中英

Maven + Vert.x-“软件包junit.framework不存在”

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

我有以下pom.xml文件:

<?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>

当我跑步时:

mvn clean package exec:java

我得到:

[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

由于我有单个测试用例,所以发生了错误:

package cdt;

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

public class HelloWorldEmbeddedTest extends TestCase {


}

但是我在<dependencyManagement>部分的pom.xml文件中引用了junit。

有人知道怎么了吗?

实施过程中的几件事:

首先 ,由于该模块使用junit的软件包,因此您还应该将其包含在<dependencies>标记中,而不是<dependencyManagement>如:

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

其次 ,请注意,虽然我找不到指定版本的junit构件的Java文档,但在我看来, 相信这个问题4.+版本的库使用了@org.junit.Test类,而不是您使用的类。类,即@junit.framework.Test 如果您的课程中有最新的软件包名称,则可能需要更改为最新的软件包名称。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM