Maven dependency for whole org.springframework

前端 未结 8 1922
滥情空心
滥情空心 2020-12-28 09:50

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.:

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-28 10:18

    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.

    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):

    
        org.springframework
        org.springframework.context
        ${org.springframework-version}
    
    
        org.springframework
        org.springframework.web.servlet
        ${org.springframework-version}
    
    
        org.springframework
        org.springframework.transaction
        ${org.springframework-version}
    
    

    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:

    
        org.springframework
        org.springframework.web.servlet
        ${org.springframework-version}
    
    
        org.springframework
        org.springframework.transaction
        ${org.springframework-version}
    
    

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

    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.

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

    mvn dependencies:list
    

    More on the dependencies plugin is on the plugin site.

    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.

提交回复
热议问题