Home > database >  maven does not have spring version 3 or version 4?
maven does not have spring version 3 or version 4?

Time:11-29

I was trying to run a legacy project using spring version 3 with build.gradle:

...
plugins {
    id 'java'
    id 'maven-publish'
    id 'war'
}

repositories {
    mavenLocal()
    maven {
        url = uri('https://repo.maven.apache.org/maven2/')
    }
}

ext {
    org_springframework_version = '3.2.18.RELEASE'
}

dependencies {
...
    implementation 'org.springframework.ldap:spring-ldap-core:2.4.1'
    implementation "org.springframework:spring-web:${org_springframework_version}"
    implementation "org.springframework:spring-webmvc:${org_springframework_version}"
    implementation "org.springframework:spring:${org_springframework_version}"
...
}
...

but getting the following error when trying to build:

Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
   > Could not find org.springframework:spring:3.2.18.RELEASE.
     Searched in the following locations:
       - file:/C:/Users/.../.m2/repository/org/springframework/spring/3.2.18.RELEASE/spring-3.2.18.RELEASE.pom
       - https://repo.maven.apache.org/maven2/org/springframework/spring/3.2.18.RELEASE/spring-3.2.18.RELEASE.pom
     Required by:
         project :

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

I checked https://repo.maven.apache.org/maven2/org/springframework/spring/ and it looks like there is no spring 3 or 4 in the repo.

I cannot use any newer spring version as there are tons of other dependencies and legacy code in the project that should be kept as is.

I am confused as to why is this the case or how to build my project now. Any help is appreciated.

PS. A little background: I have a legacy project that relies on really old tech (Stripes framework) which is straight up refusing to work with spring 5 . It is running on Java 6 now. I want to upgrade it to java 8. But spring 2.x dependency is not letting me to.

CodePudding user response:

The fullblown spring.jar hasn't been available since Spring Framework 3.0.0. Spring 2.5.6 is the last one that has the full Spring jar. Since then only the smaller modules have been available.

The versions for 5.x you see are only some top level pom.xml files which, I assume, have been published accidentally (as for 6.x they aren't there anymore).

In short remove the following line from your dependencies

implementation "org.springframework:spring:${org_springframework_version}"

So it doesn't try to resolve something that hasn't been available since Spring 2.5.6 anymore. What you should include are the dependencies for the modules you need (something like the below dependencies).

implementation "org.springframework:spring-web:${org_springframework_version}"
implementation "org.springframework:spring-webmvc:${org_springframework_version}"
implementation "org.springframework:spring-jdbc:${org_springframework_version}"
implementation "org.springframework:spring-orm:${org_springframework_version}"
implementation "org.springframework:spring-oxm:${org_springframework_version}"

As an additional note replace

maven {
        url = uri('https://repo.maven.apache.org/maven2/')
}

with

mavenCentral()

This will allow Gradle to pick a better suited mirror of Maven for your environment.

  • Related