maven子模块之间互相引入依赖,pom文件报错

还是比较菜

父项目是A,两个子项目是B和C,B中想引入C,会发现报错了,原因是我们install的顺序有问题

我建议:

先把你添加的其他依赖全部去掉,只剩下单纯的B-A,B-C的依赖,然后先 maven install父项目,把父子关系建立起来,父项目A中要包括duimaven插件的引用,例如:

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>

这样的,之后你再去添加B-C这种子项目间的依赖,应该就没问题了

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
在Java中,当两个项目(通常称为模块模块之间存在依赖关系,并且这些模块分别管理为独立的`pom.xml`文件,也就是Maven项目的构建配置文件,那么我们可以通过以下方式处理它们之间依赖: 1. **项目结构**:首先,在父POM中定义模块。在`<modules>`标签下添加模块的路径,比如 `<module>moduleA</module>` 和 `<module>moduleB</module>`。 ```xml <project> ... <modules> <module>moduleA</module> <module>moduleB</module> </modules> ... </project> ``` 2. **依赖声明**:在每个模块的`pom.xml`中,通过`<parent>`标签引用模块,同时在`<dependencies>`部分声明对其他模块依赖。例如在`moduleA`的`pom.xml`: ```xml <project> ... <parent> <groupId>your.parent.groupId</groupId> <artifactId>parentArtifactId</artifactId> <version>parentVersion</version> </parent> ... <dependencies> <dependency> <groupId>your.moduleB.groupId</groupId> <artifactId>moduleBArtifactId</artifactId> <version>moduleBVersion</version> </dependency> </dependencies> </project> ``` 3. **构建和打包**:在执行maven命令(如`mvn clean install`)时,Maven会先根据父POM中的信息设置全局的环境,然后按顺序构建所有模块。如果模块间有循环依赖,可能需要调整依赖顺序。 相关问题: 1. 如何避免模块间的循环依赖? 2. 当一个模块需要被多个其他模块依赖时,应该如何处理? 3. 在实际开发中,如何管理和更新这种多层依赖的关系?
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值