整个 org.springframework 的 Maven 依赖项 [英] Maven dependency for whole org.springframework

查看:40
本文介绍了整个 org.springframework 的 Maven 依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为所有org.springframework设置Maven依赖?

How to set Maven dependency for all org.springframework ?

我的意思是,如何在几行中做到这一点,而不是为每个模块提供依赖关系,例如:

I mean, how to do it in couple lines,instead of providing dependency for every module,e.g.:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>3.0.5.RELEASE</version>
</dependency>

等等.

谢谢你的帮助

推荐答案

正如其他答案中所述,您只想使用您实际需要的东西,例如如果你需要 Spring Web 框架,那么就得到它.但是,您可以通过进行一些依赖分析并仅指定所需依赖的最高级别,大大简化和减少 pom.xml 中列出的依赖集.

As noted in other answers, you only want to use what you actually need, e.g. if you need the Spring Web framework, then get that. However, you can greatly simplify and reduce the set of dependencies listed in your pom.xml by doing a bit of dependency analysis and only specifying the highest level of required dependency.

例如,假设您有以下依赖项(请注意,我使用的是 Spring EBR 存储库的工件 ID 而不是 Maven Central;请参阅 这篇文章了解更多关于差异的信息):

So for example, suppose you have the following dependencies (note that I'm using the artifact IDs for the Spring EBR repository instead of Maven Central; see this article for more info on the difference):

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>org.springframework.context</artifactId>
    <version>${org.springframework-version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>org.springframework.web.servlet</artifactId>
    <version>${org.springframework-version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>org.springframework.transaction</artifactId>
    <version>${org.springframework-version}</version>
</dependency>

不过,事实上,Spring Web 的东西实际上已经依赖于上下文库,所以你可以删除上下文引用:

As it happens, though, the Spring Web stuff actually already has a dependency on the context library, so you can just remove the context reference:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>org.springframework.web.servlet</artifactId>
    <version>${org.springframework-version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>org.springframework.transaction</artifactId>
    <version>${org.springframework-version}</version>
</dependency>

这将为您提供上下文库而无需专门引用它,因为它是由 Web 库中的依赖项隐式引入的.

This will get you the context library without specifically referencing it, since it's brought in implicitly by the dependency in the Web library.

如果您的 IDE 中有 IntelliJ 或 m2eclipse 或类似的东西,您可以在 IDE 中直接显示这些依赖关系,通过依赖层次结构显示,甚至在依赖关系图中,这基本上是一个 UML 图表.

If you have IntelliJ or m2eclipse or something like that in your IDE, you can get these dependencies displayed right in the IDE, either through a dependency hierarchy display or even in a dependency graph, which is basically a UML chart.

对于独立的 Maven,我认为您只需这样做:

For stand-alone Maven, I think you just do:

mvn dependencies:list

更多关于依赖插件的信息在插件网站上.

这种方法使您的依赖项非常明确,并且您的应用程序占用空间小得多,这基本上是其他人都在警告的,但可以减少您必须在 pom.xml 中列出的依赖项数量,这就是我认为的'正在尝试解决.

This approach keeps your dependencies very explicit and your application footprint much smaller, which is basically what everyone else is warning about, but can reduce the number of dependencies you have to list in your pom.xml, which is what I think you're trying to solve.

这篇关于整个 org.springframework 的 Maven 依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆