gpt4 book ai didi

java - Maven 配置文件在子模块中看不到依赖关系

转载 作者:行者123 更新时间:2023-11-29 08:51:53 25 4
gpt4 key购买 nike

我已经搜索过 SO 和 Internet,但没有成功。这就是我的简而言之:

具有 dev 和 appserv 配置文件的多模块项目。当使用 dev 配置文件时(只是 mvn clean install 因为 default=true),然后加载特定的依赖项。一个依赖项是 Child-A,它必须加载到 Child-B 中。我总是从父 POM 构建。

我在父 POM 中定义了激活的配置文件,在 Child-B 中我有相同的配置文件和依赖项。

这是我的父 POM:

<project ..>
<groupId>com.organisation</groupId>
<artifactId>project-name</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

<modules>
<module>child-b</module>
<module>child-a</module>
</modules>

<properties>
<javax.ws.rs.version>2.0</javax.ws.rs.version>
</properties>

<dependencyManagement>
<dependencies>
<!-- project dependencies -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>child-a</artifactId>
<version>${project.version}</version>
</dependency>
<!-- build dependencies -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>${javax.ws.rs.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>child-a</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>${javax.ws.rs.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</profile>

<profile>
<id>app-server</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>env</name>
<value>app-server</value>
</property>
</activation>
</profile>
</profiles>
</project>

我的调用 Child-AChild-B 模块,IDE 在构建 Child-B 时也看不到 Child-A 的类(class)。

<project ..>
<parent>
<groupId>com.organisation</groupId>
<artifactId>project-name</artifactId>
<version>1.0</version>
</parent>

<artifactId>child-b</artifactId>
<packaging>jar</packaging>

<profiles>
<profile>
<id>dev</id>
<dependencies>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>child-a</artifactId>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
</dependencies>
</profile>

<profile>
<id>app-server</id>
<dependencies>
...
</dependencies>
</profile>
</profiles>

<dependencies>
...
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
...
</dependencies>
</project>

我看不出这里有什么问题,也无法理解问题出在哪里,为什么 Child-B 没有将 Child-A 作为依赖项。在 profile 内的父级 POM 中,我试图删除 dependencyManagement,但结果仍然相同 - Child-AChild-B 模块中没有看到。显然没有配置文件一切正常。

最佳答案

在 Child-b 中,你放置了对 child-b 的依赖,而不是对 child-a 的依赖

<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>child-b</artifactId>
</dependency>

代替

<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>child-a</artifactId>
</dependency>

关于java - Maven 配置文件在子模块中看不到依赖关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22444706/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com