4

I have a relatively simple question regarding spring & hibernate maven builds.

Say I have project A, which has had all jars added to the library by the IDE during project configuration at setup time - there was no Maven POM. Everything in this project is assumed to be working without issue.

Now, take project B. This project will replicate project A, but will be configured using a Maven POM.

My question comes in the dependency configuration stage. Take this image

Project A JAR Lib

In order to replicate the lib of Project A, is it required that I manually go through the list of added JARs individually, find the correlating maven dependency at a MVN Repo, and then add them to the project POM of Project B? Or is there a 'neater' way to go about building a basic spring dependency set using maven.

Apologies if this question seems trivial, im a still at the beginner stage of building with Maven POMs.

Many thanks.

Php Pete
  • 762
  • 3
  • 14
  • 29

4 Answers4

1

It was an interesting question for me, but unfortunatly there is no decision (or I can't find it). Look this links:

http://maven.apache.org/ref/3.0.4/maven-model-builder/super-pom.html

http://maven.apache.org/ref/3.0.4/maven-model-builder/

Overriding super POM with a company-wide super/parent POM

Community
  • 1
  • 1
degr
  • 1,559
  • 1
  • 19
  • 37
1

I'am afraid the expected way is indeed to find the maven artifact for each dependency.

There is a very nice site for that : http://mvnrepository.com/

Otherwise you can indeed build a "basic spring dependency set" by creating a module with pom packaging listing all your spring dependencies and configure your parent project to depend on this module but there is no real interest to do that IMHO.

Modularity is a wonderful things (jar hell eg. version collision problems is a redundant java application problem and you should keep the finest possible granularity if you want to avoid playing with maven dependency exclusion)

Gab
  • 7,869
  • 4
  • 37
  • 68
  • Thanks Gab. I'm familiar with the mvnrepository! So you mean to create a serpate Maven POM project and have my other projects inherit from this? Sounds good to me! – Php Pete Mar 05 '15 at 14:14
  • Yes you get the idea, but again I don't think it's a good one cause your project may be already organized in different module that may not all need the whole spring framework dependencies. If the spring guys packaged it as it and not as a whole there are good reasons. – Gab Mar 05 '15 at 14:18
1

You would be correct in that there is no currently remained repository (that I know of!) which has "all the spring dependencies". Which is why you would define a Maven property for your Spring version and use it as a placeholder for all your Spring dependencies.

Also, you might not need to add ALL of these JARs, as some of them come along with another one (web comes with webmvc, iirc).

Example: Above (or below) your dependencies, you would use something like this:

<properties>
    <spring.version>4.1.5.RELEASE</spring.version>
</properties>

Then, when adding your dependencies, you can use the following:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>${spring.version}</version>
</dependency>
Schaka
  • 772
  • 9
  • 20
  • Hi Schaka, could you elaborate on what you mean - "define a maven property for your spring build"? Can this be auto-generated somehow? – Php Pete Mar 05 '15 at 14:12
1

You can use spring-framework-bom as follows:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-framework-bom</artifactId>
            <version>4.0.1.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
    </dependency>

    ...
<dependencies>

Or you can declare a pom property with the spring version:

<properties>
    <spring-version>4.0.1.RELEASE</spring-version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring-version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${spring-version}</version>
    </dependency>

    ...
<dependencies>

You can find the most common dependencies here: http://spring.io/blog/2009/12/02/obtaining-spring-3-artifacts-with-maven/

Marcelo Keiti
  • 1,200
  • 9
  • 10
  • The Bom is just a way to ease dependencyManagement eg. dependency version management but will not transitively pull the dependencies to your project – Gab Mar 05 '15 at 14:10
  • Yes, you are right. I just correct my answer. Thanks – Marcelo Keiti Mar 05 '15 at 14:18