簡體   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