gpt4 book ai didi

java - 插件依赖的Maven依赖管理

转载 作者:IT老高 更新时间:2023-10-28 20:44:14 31 4
gpt4 key购买 nike

最近,我遇到了以下问题:

当我为我的项目设置依赖项管理时,我有 child-pom 使用带有依赖项的插件,我希望与我的依赖项管理中声明的依赖项同步。

在根 pom 中,我在依赖管理中声明:

<dependencyManagement>
<dependencies>
...
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>2.4.0</version>
</dependency>
...
<dependencies>
<dependencyManagement>

在子 pom 中,我有一个需要 gwt-user 的插件:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.4.0</version>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>2.4.0</version>
</dependency>
...
</dependencies>
...
</plugin>

但是,如果我删除 gwt-maven-plugin 中使用的依赖版本,编译会失败。

还有其他方法可以实现吗?

PS:有一个相关的帖子Choosing dependency version in maven and maven plugin这没有回答我的问题

最佳答案

根据下面的链接看来是不可能的:

这是我找到的一种解决方法,我想与大家分享,以防其他人遇到同样的问题:

在我的根 pom 中,我定义了一个属性、一个依赖管理和一个插件管理:

<properties>
<gwtVersion>2.4.0</gwtVersion>
<gwtMavenPluginVersion>2.4.0</gwtMavenPluginVersion>
</properties>

<dependencyManagement>
<dependencies>
...
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
</dependency>
...
</dependencies>
</dependencyManagement>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${gwtMavenPluginVersion}</version>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
</dependency>
...
</dependencies>
...
</plugins>
...
</pluginManagement>
</build>

而在我的子pom中,使用插件管理提供的关系(见Maven2 - problem with pluginManagement and parent-child relationship),我只是声明了插件依赖:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
</plugin>

现在,如果我更改属性中的版本,它会自动影响所有直接依赖项和插件依赖项。

关于java - 插件依赖的Maven依赖管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11254356/

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