参考:
https://blog.csdn.net/ory001/article/details/119038592
Maven 项目结构如下:
PPP(父项目,带有 pom.xml)
|--common(公共模块,带 pom.xml)
|-ModuleA(模块A,带有 pom.xml)
+ModuleB(模块B,带有 pom.xml)
模块 Common, A, B 模块,设置 Parent 为 ppp的pom.xml。
模块 A和B,依赖 Common。
程序在Idea中运行正常,但是,使用 Maven 运行 mvn package 指令的时候,模块 A 和 B,报错:
cannot find symbole xxx ,其中 xxx 为公共模块中的类。
解决方法:
在 父pom.xml中,增加:
-  <build>
-   <plugins>
-    <plugin>
-     <groupId>org.springframework.boot</groupId>
-     <artifactId>spring-boot-maven-plugin</artifactId>
-     <configuration>
-      <classifier>exec</classifier>
-     </configuration>
-     <executions>
-      <execution>
-      </execution>
-     </executions>
-    </plugin>
-   </plugins>
-  </build>
在子模块A和B,添加 common 依赖的地方,增加
<scope>compile</scope>
记得检查其他的 artifactId, groupId 等是否正确。