如何解决补充Maven子模块中的循环依赖?(How to resolve cyclic dependency in supplementary Maven sub

编程入门 行业动态 更新时间:2024-10-11 21:23:47
如何解决补充Maven子模块中的循环依赖?(How to resolve cyclic dependency in supplementary Maven sub-module?)

有一个多模块Maven-3项目,其中一个子模块在所有其他模块中用作<dependency> 。 同时,所有子模块都继承自父模块。 这种结构导致循环依赖性。 我该如何解决?

项目结构相当典型:

/foo /foo-testkit /foo-core

这是父foo/pom.xml :

[...] <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <configuration> <configLocation>checkstyle/checks.xml</configLocation> </configuration> <dependencies> <dependency> <groupId>${project.groupId}</groupId> <artifactId>foo-testkit</artifactId> <version>${project.version}</version> </dependency> </dependencies> <executions> <execution> <phase>prepare-package</phase> <goals> <goal>check</goal> </goals> </execution> </executions> </plugin> </plugins> </build> [...]

在父foo/pom.xml我指定了必须在每个子模块中执行checkstyle插件的方式和时间。 但我不需要在foo-testkit执行checkstyle,这是一个继承自foo的子模块,但同时也是一个依赖项。

There is a multi-module Maven-3 project, where one of sub-modules is used as <dependency> in all other modules. At the same time, all sub-modules inherit from parent module. Such a structure leads to cyclic dependency. How can I resolve it?

Project structure is rather typical:

/foo /foo-testkit /foo-core

This is parent foo/pom.xml:

[...] <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <configuration> <configLocation>checkstyle/checks.xml</configLocation> </configuration> <dependencies> <dependency> <groupId>${project.groupId}</groupId> <artifactId>foo-testkit</artifactId> <version>${project.version}</version> </dependency> </dependencies> <executions> <execution> <phase>prepare-package</phase> <goals> <goal>check</goal> </goals> </execution> </executions> </plugin> </plugins> </build> [...]

In parent foo/pom.xml I specify how and when checkstyle plugin has to be executed in every sub-module. But I don't need checkstyle to be executed in foo-testkit, which is a sub-module inheriting from foo, but is at the same time a dependency..

最满意答案

一种方法是通过将以下内容添加到foo-testkit的pom.xml文件来禁用模块foo-testkit的checkstyle插件。

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <configuration> <skip>true</skip> </configuration> </plugin>

如果这不符合您的喜好,另一种方法是将checkstyle插件配置从build / plugins移动到父pom.xml文件中的build / pluginManagment / plugins。 然后在每个模块中执行checkstyle,将其添加到每个模块的pom.xml文件的build / plugins部分:

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> </plugin>

这将调用该模块的插件,并将应用pluginManagement部分下的父pom.xml中指定的配置。 您可以通过在该模块上运行mvn help:effective-pom来验证是否正常工作。

One way is to disable the checkstyle plugin for module foo-testkit by adding the below to foo-testkit's pom.xml file.

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <configuration> <skip>true</skip> </configuration> </plugin>

If that is not to your liking, another way is to move the checkstyle plugin configuration from build/plugins to build/pluginManagment/plugins in the parent pom.xml file. Then in each module you want checkstyle executed, add this to the build/plugins section of each module's pom.xml file:

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> </plugin>

This invokes the plugin for that module and the configuration specified in the parent pom.xml under the pluginManagement section will be applied. You can verify that is working correctly by running mvn help:effective-pom on that module.

更多推荐

本文发布于:2023-08-07 16:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465342.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何解决   模块   Maven   resolve   dependency

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!