【发布时间】:2019-01-01 18:03:15
【问题描述】:
我知道这个问题已经被问过很多次了,但是我读过的方法对我不起作用。我试过this,但还是不行。
我有一个依赖于另一个子项目(B) 的子项目(A)。
两个子项目都包含在父目录中,父目录中的 pom.xml(将 A 和 B 声明为模块)位于各自的子目录中。
使用 maven-assembly-plugin 编译和安装项目可以正常工作,但是当我尝试测试 A 时,它无法识别 B 中的类。 我试过先安装它然后测试,但它仍然找不到类。我错过了什么?
错误:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile
(default-testCompile) on project (A)
[ERROR] TestService.java:[8,17] cannot find symbol
[ERROR] symbol: class **Model** (the class I'm referencing in B)
[ERROR] location: class **TestService**
(test in A that tests the class in ../service/src/main/java/Service.java)
编辑:
/项目
--/service(这取决于模型;这也是我要测试的)
---/src
----/主
-----/java
------/Service.java
----/测试
-----/java
------/TestService.java
--/model(独立)
---/src
----/主
-----/java
------/Model.java
--/entry(这取决于服务;整个项目的入口点)
--pom.xml (父 pom)
三个项目里面都有自己的pom.xml。
/model/pom.xml 不包含依赖项和插件
这里是父: 父/pom.xml
...
<modules>
<module>entry</module>
<module>service</module>
<module>model</module>
</modules>
这里是条目:
/service/pom.xml
...
<parent>
<groupId>com.some.project</groupId>
<artifactId>project</artifactId>
<version>xx</version>
</parent>
<artifactId>entry</artifactId>
<packaging>jar</packaging>
<version>xx</version>
<name>entry</name>
<build>
...
<!--assembly plugin is declared here-->
</build>
<dependencies>
<dependency>
<groupId>com.some.project</groupId>
<artifactId>service</artifactId>
<version>xx</version>
</dependency>
</dependencies>
这里是服务:
/service/pom.xml
...
<parent>
<groupId>com.some.project</groupId>
<artifactId>project</artifactId>
<version>xx</version>
</parent>
<artifactId>service</artifactId>
<packaging>jar</packaging>
<version>xx</version>
<name>service</name>
<dependencies>
<dependency>
<groupId>com.some.project</groupId>
<artifactId>model</artifactId>
<version>xx</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
【问题讨论】:
-
请显示代码或错误信息。