[英]Can't resolve class dependencies in a MAVEN project with Child/Modules (seen in Eclipse and mnv CLI)
I have an Eclipse Maven Project (parent) that hosts three Maven MODULES (it's children). 我有一个Eclipse Maven项目(父项目),该项目承载三个Maven模块(是孩子)。 Only the child MODULES have code under "src/main/java/..." (ie the PARENT is just a stub place holder for the children).
只有子模块在“ src / main / java / ...”下具有代码(即,父母只是孩子的存根占位符)。 Each MODULE is independent of one another... I just set it up that way to reduce clutter.
每个模块彼此独立...我只是以减少杂乱的方式进行设置。 =:)
= :)
Now the project structure didn't start out this way. 现在,项目结构并不是以这种方式开始的。 Initially it was just one big PARENT and no child MODULES;
最初,它只是一个大的父级,没有子模块。 and everything worked fine.
而且一切正常。 But then I reorganized things within Eclipse (again to reduce clutter) using various moves/refactors , and things stopped working.
但是后来我使用各种移动/重构方法重新整理了Eclipse中的内容(再次减少混乱),并且一切都停止了工作。
The Problem : My source code can't find imported classes now, so my dependency resolution became problematic somewhere. 问题 :我的源代码现在找不到导入的类,因此我的依赖项解析在某处变得有问题。 And the problem isn't just seen in Eclipse, but also when I run, say, 'mvn clean install' from the CLI.
问题不仅出现在Eclipse中,还出现在我从CLI运行“ mvn clean install”时。 So I suspect something is wrong with the set of POM files that resulted from my moves/refactors.
因此,我怀疑由我的移动/重构导致的POM文件集出了问题。
Here they are (the PARENT and one CHILD). 他们在这里(父母和一个孩子)。 Am I missing something, or is something incorrect?
我错过了什么,还是不正确的东西? Maybe I should check something Eclipse, too?
也许我也应该检查Eclipse? Note that I embedded a couple of little in-line questions inside the POM files below.
请注意,我在下面的POM文件中嵌入了一些内联的小问题。 :)
:)
The PARENT pom.xml file: 父 pom.xml文件:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>someName</name>
<packaging>pom</packaging>
<groupId>someParentGroupId</groupId>
<artifactId>someParentArtifactId</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<jdk.version>1.7</jdk.version>
<example-core.version>0.9.3</example-core.version>
<!-- Intended to be used by some Child/Module.
I hope PARENT/CHILD POM inheritance works that way? -->
</properties>
<dependencies>
<!-- Dependencies are all in the Children/Modules -->
</dependencies>
<!-- ################### BUILD SETTINGS BEGIN ##################### -->
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin> <!-- Used to create an UBER/FAT-JAR. -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>uber-${project.artifactId}-${project.version}</finalName>
</configuration>
</plugin>
</plugins>
</build>
<!-- ################### BUILD SETTINGS END ####################### -->
<modules>
<module>childModule1</module>
<module>childModule2</module>
<module>chileModule3</module>
</modules>
</project>
Example CHILD pom.xml file: CHILD pom.xml文件示例:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>someParentGroupId</groupId>
<artifactId>someParentArtifactId</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>someChildArtifactId</artifactId>
<!-- I noticed this missing in the Children/Module POM. Is that okay?
<name>
</name>
-->
<dependencies>
<dependency>
<groupId>org.example.somgGroupId</groupId>
<artifactId>example-core</artifactId>
<version>${example-core.version}</version>
</dependency>
</dependencies>
</project>
Again, the problem seems simple. 同样,问题似乎很简单。 I can't resolve imports (so, naturally, my Classes have import-ralated errors).
我无法解析导入(因此,很自然,我的课程有导入相关的错误)。
Thank you in advance! 先感谢您!
name is not a mandatory attribute in pom.xml. 名称不是pom.xml中的必需属性。
I assume someChildArtifactId is given as an example. 我假设以someChildArtifactId为例。 If not, the same artifact id should be used in the parent pom.
如果不是,则应在父pom中使用相同的工件ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.