【问题标题】:Error to run a Maven with JUnit project in Eclipse在 Eclipse 中使用 JUnit 项目运行 Maven 时出错
【发布时间】:2017-07-18 03:23:40
【问题描述】:

当我尝试在 Eclipse 项目中运行带有 JUnit 测试的 Maven 时,出现以下错误:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building exemplo-maven 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ exemplo-maven ---
[INFO] Deleting C:\Users\vcamargo\workspace\exemplo-maven\target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ exemplo-maven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ exemplo-maven ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Users\vcamargo\workspace\exemplo-maven\target\classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ exemplo-maven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ exemplo-maven ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Users\vcamargo\workspace\exemplo-maven\target\test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ exemplo-maven ---
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-booter/2.12.4/surefire-booter-2.12.4.pom
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/maven-surefire-common/2.12.4/maven-surefire-common-2.12.4.pom
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/reporting/maven-reporting-api/2.0.9/maven-reporting-api-2.0.9.pom
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-toolchain/2.0.9/maven-toolchain-2.0.9.pom
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/maven-plugin-annotations/3.1/maven-plugin-annotations-3.1.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.470 s
[INFO] Finished at: 2017-02-27T10:08:30-03:00
[INFO] Final Memory: 19M/153M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project exemplo-maven: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test failed: Plugin org.apache.maven.plugins:maven-surefire-plugin:2.12.4 or one of its dependencies could not be resolved: Failed to collect dependencies at org.apache.maven.plugins:maven-surefire-plugin:jar:2.12.4 -> org.apache.maven.surefire:surefire-booter:jar:2.12.4: Failed to read artifact descriptor for org.apache.maven.surefire:surefire-booter:jar:2.12.4: Could not transfer artifact org.apache.maven.surefire:surefire-booter:pom:2.12.4 from/to central (https://repo.maven.apache.org/maven2): RSA premaster secret error: SunTls12RsaPremasterSecret KeyGenerator not available -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException

按照我的 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.algaworks.curso</groupId>
    <artifactId>exemplo-maven</artifactId>
    <version>1.0.0-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <killAfter>-1</killAfter>
                    <mainClass>com.algaworks.curso.Main</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

我的主要课程:

package com.algaworks.curso;

public class Main {

    public static void main(String[] args) {
        System.out.println("Hello Maven");
    }

}

最后是我的测试课:

package com.algaworks.curso;

import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class FibonacciTest {

    @Test
    public void deve_retornar_fibonacci_posicao_1() {
        assertEquals(1L, 1L);
    }

}

当我单独运行我的测试类时,它运行完美。如果我尝试在没有测试的情况下运行 Maven 项目(目标:exec:java),它也会运行完美。

错误发生在我尝试使用 JUnit 测试运行 Maven 项目时(目标:干净的项目)。

【问题讨论】:

  • 当您尝试从终端运行它时会发生什么?
  • 我不知道如何从终端运行它。我在 Eclipse 中使用 Maven 插件,如果我配置为在没有测试的情况下运行(目标:exec:java),它会完美运行。
  • 尝试从包含pom.xml的项目目录运行mvn clean install(安装maven后)

标签: java eclipse maven junit


【解决方案1】:

错误表示无法解析由surefire插件直接或间接使用的依赖项。我从来没有遇到过这个错误,但是,从位置删除你的 maven-surefire-plugin 文件夹:“.m2\repository\org\apache\maven\plugins” 并重新运行构建,它将自动重新下载所有插件文件。 确保在删除之前备份文件夹,以便分析丢失的内容。

【讨论】:

    【解决方案2】:

    从您发布的日志看来,问题不在于您的 JUnit 测试用例,而是您的 maven 无法下载少量工件。在 repo 中,我可以看到所需版本的 maven surefire booter jar ..我猜网络防火墙或连接存在一些问题...我们可以尝试重新连接到网络然后运行目标吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多