繁体   English   中英

如何在Maven多模块项目中添加test-jar和jar作为依赖项?

[英]How to add test-jar and jar as dependency in a maven multimodule project?

我有一个形式的Maven多模块项目

  • 主要
    • 询问
    • ...
    • 存储
      • 存储配置
      • 存储工具
      • 普通存储
    • 工具

我有一个com.vnera.storage.config.ElasticsearchEmbedded.java类驻留在storage-config测试文件夹中,该类我想在test范围内的TestStorageUtils类中TestStorageUtils storage-utils 在主要阶段, storage-utils也需要storage-config

在查询模块中,我添加了storage-utils test-jar依赖项。 但是每当我尝试从query模块中的测试访问TestStorageUtils时。 它引发了以下错误。 所有编译运行正常。

java.lang.NoClassDefFoundError: com/van/storage/config/ElasticsearchEmbedded

    at com.van.storage.utils.TestStorageUtils.setUp(TestStorageUtils.java:92)
    at com.van.query.SearchUtilsTests.setUp(SearchUtilsTests.java:90)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.ClassNotFoundException: com.van.storage.config.ElasticsearchEmbedded
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 17 more

必要的pom放在下面:

有人可以让我知道出了什么问题吗,我该如何解决呢?

Maven版本-3.5.3

query模块还需要声明storage-config的test-jar依赖项。

 <dependency>
            <groupId>com.van</groupId>
            <artifactId>storage-config</artifactId>
            <version>${main.version}</version>
            <classifier>tests</classifier>
            <scope>test</scope>
            <type>test-jar</type>
        </dependency>

暂无
暂无

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

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