【问题标题】:I am unable to add Junit Maven Dependency in Eclipse我无法在 Eclipse 中添加 Junit Maven 依赖项
【发布时间】:2020-01-30 10:34:35
【问题描述】:

我创建了一个 Maven Java 项目。我正在为 iOS 应用程序进行自动化测试。我无法解决与 Junit 相关的依赖问题。 我的测试类在 src/test/java 下

这是我的 pom.xml

<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>com.hft.sammar</groupId>
<artifactId>AppiOSTests</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
    <junit.jupiter.version>5.2.0</junit.jupiter.version>
</properties>
<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <goals>
                        <goal>test-jar</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <release>12</release>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.test.MainClassName</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <!-- packaging phase -->
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.141.59</version>
    </dependency>
    <dependency>
        <groupId>io.appium</groupId>
        <artifactId>java-client</artifactId>
        <version>7.2.0</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.5.0</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.5.0</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.5.0</version>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>${junit.jupiter.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-params</artifactId>
        <version>${junit.jupiter.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>${junit.jupiter.version}</version>
        <scope>test</scope>
    </dependency>
</dependencies>

在控制台中显示

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project AppiOSTests: Compilation failure: Compilation failure: 

以及其他一些陈述,例如 包 org.junit 不存在 包org.junit.jupiter.api不存在等等

【问题讨论】:

  • 我将 POM.xml 复制并粘贴到示例项目中,它构建时没有出现错误。
  • 这对我来说不起作用。会有问题吗?
  • 在您的 Maven 用户设置中,您要指向哪个存储库? org.junit.jupiter.api 包是否存在?
  • 在哪里可以看到 maven 用户设置?
  • MAVEN_HONE\conf\settings.xml

标签: java eclipse maven junit pom.xml


【解决方案1】:

几乎所有 Maven 问题都可以通过以下方式之一解决:

  1. Right Click your Project -> Run As... -> Maven build... -> 在“目标”中输入dependency:resolve clean install -> 点击OK

  2. Right Click your Project in Project Explorer -> Maven -> Update Project... -> 检查"Force Update of Snapshots/Releases" -> 点击OK

【讨论】:

    【解决方案2】:

    只需清理项目并再次构建它。 .m2/ 存储库中可能存在依赖版本冲突。

    如果执行上述步骤后问题仍然存在。删除 .m2 文件夹并重新启动您的工作区并构建项目。

    这应该可以解决您的问题。

    【讨论】:

      猜你喜欢
      • 2016-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-15
      • 2013-02-13
      • 1970-01-01
      • 1970-01-01
      • 2013-11-07
      相关资源
      最近更新 更多