Maven - 测试中的不同依赖版本

2023-12-11

我遇到了类似的问题Maven 2 - 测试和编译中的不同依赖版本但那里指定的答案不起作用。

在我的项目中,我需要依赖 Hadoop 的 Cloudera 发行版和用于 JUnit 测试的“vanilla”版本,因为前者仅适用于 *nix。

当我尝试执行我的应用程序时,我得到Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/conf/Configuration。当我从 Maven 或 Eclipse 运行 JUnit 测试时,一切正常。如果我注释掉test依赖项,应用程序成功运行。

为什么是compiletest依赖项未注释?

    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-core</artifactId>
        <version>0.20.2-cdh3u2</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-core</artifactId>
        <version>1.0.0</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-test</artifactId>
        <version>1.0.0</version>
        <scope>test</scope>
    </dependency>

mvn dependency:list如下所示。这compile范围版本根本不显示:

[INFO] The following files have been resolved:
[INFO]    ant:ant:jar:1.6.5:test
[INFO]    aopalliance:aopalliance:jar:1.0:compile
[INFO]    asm:asm:jar:3.3.1:compile
[INFO]    cglib:cglib:jar:2.2.2:compile
[INFO]    ch.qos.logback:logback-classic:jar:1.0.0:compile
[INFO]    ch.qos.logback:logback-core:jar:1.0.0:compile
[INFO]    com.google.guava:guava:jar:r08:compile
[INFO]    com.h2database:h2:jar:1.3.164:test
[INFO]    com.jolbox:bonecp:jar:0.7.1.RELEASE:compile
[INFO]    com.sun.jersey:jersey-core:jar:1.11:test
[INFO]    commons-beanutils:commons-beanutils:jar:1.7.0:test
[INFO]    commons-beanutils:commons-beanutils-core:jar:1.8.0:test
[INFO]    commons-cli:commons-cli:jar:1.2:test
[INFO]    commons-codec:commons-codec:jar:1.4:test
[INFO]    commons-collections:commons-collections:jar:3.2.1:test
[INFO]    commons-configuration:commons-configuration:jar:1.6:test
[INFO]    commons-digester:commons-digester:jar:1.8:test
[INFO]    commons-el:commons-el:jar:1.0:test
[INFO]    commons-httpclient:commons-httpclient:jar:3.0.1:test
[INFO]    commons-lang:commons-lang:jar:2.4:test
[INFO]    commons-logging:commons-logging:jar:1.1.1:compile
[INFO]    commons-net:commons-net:jar:1.4.1:test
[INFO]    hsqldb:hsqldb:jar:1.8.0.10:test
[INFO]    junit:junit:jar:4.10:test
[INFO]    mysql:mysql-connector-java:jar:5.1.18:compile
[INFO]    net.java.dev.jets3t:jets3t:jar:0.7.1:test
[INFO]    net.sf.kosmosfs:kfs:jar:0.3:test
[INFO]    org.apache.commons:commons-math:jar:2.1:test
[INFO]    org.apache.ftpserver:ftplet-api:jar:1.0.0:test
[INFO]    org.apache.ftpserver:ftpserver-core:jar:1.0.0:test
[INFO]    org.apache.ftpserver:ftpserver-deprecated:jar:1.0.0-M2:test
[INFO]    org.apache.hadoop:hadoop-core:jar:1.0.0:test
[INFO]    org.apache.hadoop:hadoop-test:jar:1.0.0:test
[INFO]    org.apache.mina:mina-core:jar:2.0.0-M5:test
[INFO]    org.codehaus.jackson:jackson-core-asl:jar:1.0.1:test
[INFO]    org.codehaus.jackson:jackson-mapper-asl:jar:1.0.1:test
[INFO]    org.eclipse.jdt:core:jar:3.1.1:test
[INFO]    org.hamcrest:hamcrest-core:jar:1.1:test
[INFO]    org.liquibase:liquibase-core:jar:2.0.3:test
[INFO]    org.liquibase.ext:liquibase-slf4j:jar:0.0.1:test
[INFO]    org.mortbay.jetty:jetty:jar:6.1.26:test
[INFO]    org.mortbay.jetty:jetty-util:jar:6.1.26:test
[INFO]    org.mortbay.jetty:jsp-2.1:jar:6.1.14:test
[INFO]    org.mortbay.jetty:jsp-api-2.1:jar:6.1.14:test
[INFO]    org.mortbay.jetty:servlet-api:jar:2.5-20081211:test
[INFO]    org.mortbay.jetty:servlet-api-2.5:jar:6.1.14:test
[INFO]    org.slf4j:jcl-over-slf4j:jar:1.6.4:compile
[INFO]    org.slf4j:log4j-over-slf4j:jar:1.6.4:compile
[INFO]    org.slf4j:slf4j-api:jar:1.6.4:compile
[INFO]    org.springframework:spring-aop:jar:3.1.1.RELEASE:compile
[INFO]    org.springframework:spring-asm:jar:3.1.1.RELEASE:compile
[INFO]    org.springframework:spring-beans:jar:3.1.1.RELEASE:compile
[INFO]    org.springframework:spring-context:jar:3.1.1.RELEASE:compile
[INFO]    org.springframework:spring-context-support:jar:3.1.1.RELEASE:compile
[INFO]    org.springframework:spring-core:jar:3.1.1.RELEASE:compile
[INFO]    org.springframework:spring-expression:jar:3.1.1.RELEASE:compile
[INFO]    org.springframework:spring-jdbc:jar:3.1.1.RELEASE:compile
[INFO]    org.springframework:spring-test:jar:3.1.1.RELEASE:test
[INFO]    org.springframework:spring-tx:jar:3.1.1.RELEASE:compile
[INFO]    org.springframework.data:spring-data-hadoop:jar:1.0.0.BUILD-SNAPSHOT:c
ompile
[INFO]    oro:oro:jar:2.0.8:test
[INFO]    tomcat:jasper-compiler:jar:5.5.12:test
[INFO]    tomcat:jasper-runtime:jar:5.5.12:test
[INFO]    xmlenc:xmlenc:jar:0.52:test

您想要的内容对于 Maven 3 不再有效(这曾经对 Maven 2 有效)。 Maven 3 将尝试获取最近的依赖项,从而有效地确保编译和测试阶段仅使用编译或测试范围的依赖项之一。

在你的情况下org.apache.hadoop:hadoop-core:1.0.0:test覆盖org.apache.hadoop:hadoop-core:0.20.2-cdh3u2:compile因此成为最近的依赖项。运行时您可能会看到 Maven 显示以下警告mvn dependency:list目标,这暗示这是您的项目模型中的一个问题:

[警告]“dependency.dependency.(groupId:artifactId:type:classifier)”必须是 独特:org.apache.hadoop:hadoop-core:jar -> 版本 0.20.2-cdh3u2 与 1.0.0 @ 行 xyz,列 xyz

要“修复”此问题,最好将测试拆分为一个单独的项目,该项目的项目模型可以定义一组单独的测试依赖项。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Maven - 测试中的不同依赖版本 的相关文章

随机推荐

  • 对 2D 列表使用 .strip()

    第一个问题 我想知道如何在二维列表中使用 strip 函数 以便在列表内每个列表的每个元素中 您可以删除字符串内无用的空格 这是我在 shell 中的尝试 gt gt gt questions 1986 Baby Shaw Welcome
  • 如何使用变量作为对象初始化程序中的键

    在我正在工作的应用程序中 服务器页面用于接收输入的名称作为其值的键 用ajax可以做到这一点吗 在此示例中 thisName 被视为文字字符串 table each function this delegate input focusout
  • 在 SymPy 中将 ** 替换为 Math.pow

    我有一个 Python 中的 SymPy 表达式 我想将其复制并粘贴到 Java 源代码中 问题是求幂有不同的表示法 Java用途Math pow a b Python使用a b 所以我的问题是 有没有办法以 Java 格式 打印 SymP
  • libgdx 中的背景透明度

    如果我在Android中使用libgdx 如何使屏幕背景透明 我尝试使用的代码不起作用 Gdx gl glClearColor 0 0 0 0 Gdx gl glClear GL10 GL COLOR BUFFER BIT GL10 GL
  • ActionError 未显示

    我想加载我的Error jsp in my ErrorDiv if Action类返回错误 我正在执行 AJAX 调用 JS success function result if result success alert Database
  • Facebook 分享,标题未分享

    转到以下网址 共享消息中未显示标题 我是否正确使用它或者它是 facebook api 中的错误 问候 潘卡伊 我很确定 Google 通过 JavaScript 更改了页面的 Title 属性 如果您查看其搜索结果页面的源代码 您会发现
  • MATLAB:频率分布

    我在一个文本文件中对 500 个数值 范围从 1 到 25000 进行了原始观察 我希望在 MATLAB 中进行频率分布 我确实尝试过直方图 hist 但是我更喜欢频率分布曲线而不是块和条形图 任何帮助表示赞赏 如果将两个输出参数传递给HI
  • 如何在 Symfony2 中设置表单字段的默认值?

    有没有一种简单的方法来设置文本表单字段的默认值 你可以设置默认值empty data builder gt add myField number empty data gt Default value
  • twilio python 模块版本 2.0.8 中缺少 twilio.rest?

    Twilio python 快速入门指南说使用名为 twilio rest 的子模块 但是今天通过安装 twilio 模块后sudo pip install twilio安装了版本 2 0 8 的 twilio 模块中似乎没有名为 rest
  • 如何以编程方式在 EditText 上设置焦点(并显示键盘)

    我有一个布局 其中包含一些如下视图
  • 从 MediaStore 查询播放列表

    我正在尝试从 MediaStore 查询设备中的播放列表 我已经关注了之前提出的问题 但没有得到答案 这就是我查询播放列表的方式 public void addToPlaylist long playlistId Context conte
  • 如何单独显示数字?

    假设我在 matplotlib 中有两个图形 每个图形一个图 import matplotlib pyplot as plt f1 plt figure plt plot range 0 10 f2 plt figure plt plot
  • 来自字典的数据帧,具有自动日期解析功能

    我正在从字典序列创建一个 Pandas DataFrame 这些词典很大而且有些异构 有些字段是日期 我想自动检测并解析日期字段 这可以通过以下方式实现 df0 pd Dataframe from dict dicts df0 to csv
  • 关闭窗口 - 但不停止程序 - JAVA

    在我的程序中 如果发生某个操作 它会打开一个窗口 当我在此窗口中填写信息并输入按钮后 窗口将出现 dispose 该窗口是在我的主程序之外的程序中拾取的 但是当我关闭该窗口时 我的主程序将停止 我怎样才能防止这种情况发生 感谢您的帮助 您可
  • 使用NVM在gitlab-ci中安装特定的nodejs版本

    当我尝试使用 gitlab ci 安装 NVM 时 收到以下错误消息 gitlab ci yml 文件 stages test Testing tags docker stage test image ubuntu 18 04 before
  • 为 Node.js 应用程序构建 docker 映像在代理后面失败

    我在 docker 构建期间遇到了 npm 问题 我是一家公司代理的幕后黑手 阅读了大约 30 篇解决类似问题的文章 以及 stackoverflow 帖子 然而我仍然无法克服这一点 我能够 npm install 项目并在 docker
  • Google Apps 脚本停止从雅虎财经抓取数据

    用于从雅虎财经抓取历史数据的 Google Apps 脚本代码昨天停止工作 它突然给出错误 没有数据 data length 0 我认为错误出现在获取 JSON 时的第 8 行脚本中 但我没有必要的技能来修复它 如果您能帮助解决问题 我们将
  • 将数据框重塑为宽形状

    数据包含两个变量 id 和grade 每个id可以有多个记录 每个年级 dat lt data frame id c 1 1 1 2 2 2 2 3 3 4 5 5 5 grade c a b c a a b b d f c a e f 我
  • phpunit 无法在全新安装的 laravel 5.7 上运行

    我新安装的 Laravel 遇到问题 当我尝试使用时phpunit运行默认命令ExampleTest php 我懂了error D Laravel Rahimi0151 gt phpunit PHP Warning continue tar
  • Maven - 测试中的不同依赖版本

    我遇到了类似的问题Maven 2 测试和编译中的不同依赖版本但那里指定的答案不起作用 在我的项目中 我需要依赖 Hadoop 的 Cloudera 发行版和用于 JUnit 测试的 vanilla 版本 因为前者仅适用于 nix 当我尝试执