gpt4 book ai didi

java - Maven如何让插件执行继承项目依赖

转载 作者:行者123 更新时间:2023-11-30 07:12:02 26 4
gpt4 key购买 nike

我正在使用 Maven,我想执行一个插件而不重复一些必需的依赖项:

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.5</version>

<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.168</version>
</dependency>
<!-- ^^^ unnecessary duplication, IMO, because the project
already imports the dependency below -->
</dependencies>

<!-- ... -->
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.168</version>
</dependency>
</dependencies>

在上面的示例中,我想省略 com.h2database:h2 依赖项,因为我已经在项目中指定了它。这可以做到吗?怎么办?

最佳答案

您可以像这样在父级中使用 pluginManagement block 来做到这一点:

<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.5</version>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.168</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>

在你的 child 中,你只需要像这样使用执行:

 <build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<executions>
<execution>
....
</execution>
</executions>
</plugin>
</plugins>
</build>

这将解决您仅在一个地方维护补充类路径依赖项 (h2) 的问题。

关于java - Maven如何让插件执行继承项目依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20637454/

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