gpt4 book ai didi

java - Maven 测试编译在类路径中找不到类

转载 作者:太空宇宙 更新时间:2023-11-04 13:11:17 25 4
gpt4 key购买 nike

我有一个带有这个 pom 的小项目...

<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.example.shipcloud</groupId>
<artifactId>shipcloud-api</artifactId>
<description>The Java API for ShipCloud.</description>
<version>1.0-SNAPSHOT</version>
<prerequisites>
<maven>3.0</maven>
</prerequisites>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.compiler.source.version>1.8</project.compiler.source.version>
<project.compiler.target.version>1.8</project.compiler.target.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<!-- More Matchers than the default version in JUnit -->
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.2.0.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>2.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

在 Eclipse 中,一切正常,测试工作(使用 Maven 找不到的类),但是当我尝试通过 Maven 全新安装它时,我收到一个错误,它无法在这一行中找到 AbstractCharSequenceAssert (AssertJ 的一部分)(这是另一个公共(public)类下面的类):

class UrlParameterStringAssert extends AbstractCharSequenceAssert<UrlParameterStringAssert, String> {

INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR :
[INFO] ------------------------------------------------------------ [ERROR] /home/fschaetz/workspaces/workspace5/.../shipcloud-api/src/test/java/com/example/shipcloud/rest/shipcloud/domain/AddressSearchFieldsTest.java:[103,39] error: cannot find symbol [ERROR] symbol: class AbstractCharSequenceAssert

我查看了调试输出,当运行 testCompile 时,AssertJ jar 实际上位于提供给编译器的类路径上:

-classpath ...:/home/fschaetz/.m2/repository/org/assertj/assertj-core/2.2.0/assertj-core-2.2.0.jar:...

(文件存在、可读、包含类并且在 Eclipse 中工作正常)。

我尝试过干净(maven/eclipse)、在项目上运行更新等,但似乎没有任何效果。当我尝试在 jenkins 中运行 Maven 安装时,也会发生同样的事情,顺便说一句。

造成麻烦的类的导入是......

import static de.assona.rest.shipcloud.domain.UrlParameterStringAssert.assertThat;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.assertj.core.api.AbstractCharSequenceAssert;
import org.junit.Before;
import org.junit.Test;

有什么想法吗?

最佳答案

老实说,我不知道为什么问题是什么(并且很高兴有人能解释它),但是 WAS 是这两个类是在同一个文件中定义的......

public class AddressSearchFieldsTest {

... some testing ...

}

class UrlParameterStringAssert extends AbstractCharSequenceAssert<UrlParameterStringAssert, String> {

... a custom Assertion class...

}

通常我不希望出现这样的问题(因为在同一个文件中声明非公共(public)类应该没有问题),但不知何故,maven 不喜欢它。将 UrlParameterStringAssert 移至其自己的文件解决了该问题。很想知道为什么。

关于java - Maven 测试编译在类路径中找不到类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33933709/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com