In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to achieve the test dependency relationship between Java module and inter-module Maven". In daily operation, I believe that many people have doubts about how to achieve the test dependency relationship between Java module and inter-module Maven. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the question of "how to achieve the test dependency relationship between Java module and inter-module Maven". Next, please follow the editor to study!
I have a multi-module project using Maven and Java. I now want to migrate to Java 9-10-11 and implementation modules (such as the JSR 376:Java platform module system). With the project already made up of Maven modules, and dependencies straight, it is straightforward to create module descriptors for the project.
Each Maven module now has its own module descriptor (module-info.java) in the src/main/java folder. There are no module descriptors for test classes.
However, I stumbled upon a problem I had been unable to solve and did not find any description of how to solve it: how can I have inter-module? testing dependencies on Maven and Java modules?
In my example, I have a "common" Maven module that contains interfaces or abstract classes (but no concrete implementation). In the same Maven module, I have summary tests to ensure that the appropriate behavior implements these interfaces / abstract classes. Then, there are one or more sub-modules, interface implementation / abstract classes and abstract tests of extensions.
However, the Maven build submodule that attempts to execute the test phase will fail:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:testCompile (default-testCompile) on project my-impl-module: Compilation failure: Compilation failure: [ERROR] C:\ projects\ com.example\ my-module-test\ my-impl-module\ src\ test\ java\ com\ example\ impl\ FooImplTest.java: [42.25] error: cannot find symbol [ERROR] symbol: class FooAbstractTest [ERROR] location: package com.example.common
I suspect this is because the test is not part of the module. Even if Maven does some "magic" tests to execute the module, it won't test the module I rely on (for some reason). How can I solve this problem?
The structure of the project is as follows:
├─── my-common-module │ ├─── pom.xml │ └─── src │ ├─── │ │ └─── java │ │ ├─── com │ └─── example │ └─── common │ ├─── AbstractFoo.java (abstract Implements Foo) │ └─── Foo.java (interface) │ │ └─── module-info.java (my.common.module: exports com.example.common) │ └─── test │ └─── java │ └─── com │ └─── example │ └─── common │ └─── FooAbstractTest.java (abstract class Tests Foo) ├─── my-impl-module │ ├─── pom.xml │ └─── src │ ├─── main │ │ java │ │ ├─── com │ └─── example │ └─── impl │ └─── FooImpl.java (extends AbstractFoo) │ │ └─── module-info.java (my.impl.module: requires my.common.module) │ └─── test │ └─── java │ └─── │ └─── example │ └─── impl │ └─── FooImplTest.java (extends FooAbstractTest) └─── pom.xml
The dependency my-impl-module/pom.xml is as follows:
Com.example my-common-module compile com.example my-common-module tests test junit junit test
Note: the above is a project I created to prove this problem. I will try to update the questions for the complete project. The real project is a much more complex master branch found here, but not yet modular.
PS: there's nothing wrong with the code itself, everything uses the normal classpath (that is, compile and run. In IntelliJ).
At this point, the study on "how to implement the test dependency relationship between Java module and inter-module Maven" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.