1

I'm new to maven. My team and I are trying to work with maven over git, but when I share my code over git, the .classpath file has a dependency that is pointing to my user location:

<classpathentry kind="lib" path="C:/Users/MY_USERNAME/.m2/repository/org/springframework/security/spring-security-crypto/5.1.0.RELEASE/spring-security-crypto-5.1.0.RELEASE.jar" sourcepath="C:/Users/MY_USERNAME/.m2/repository/org/springframework/security/spring-security-crypto/5.1.0.RELEASE/spring-security-crypto-5.1.0.RELEASE-sources.jar">
    <attributes>
        <attribute name="maven.pomderived" value="true"/>
        <attribute name="maven.groupId" value="org.springframework.security"/>
        <attribute name="maven.artifactId" value="spring-security-crypto"/>
        <attribute name="maven.version" value="5.1.0.RELEASE"/>
        <attribute name="maven.scope" value="compile"/>
    </attributes>
</classpathentry>

This causes config issues for my team members.

  • Is there a way the add the .m2 folder in my project and then reference it in the build path?
  • Is that recommended?

I don't want to exclude my .classpath file because I want my team members to receive all the build path configurations, without having to do it themselves.

lealceldeiro
  • 14,342
  • 6
  • 49
  • 80
chinloyal
  • 1,023
  • 14
  • 42

1 Answers1

0

Maven comes bundled with an Eclipse plugin that allows you to easily maintain your .classpath file based on your pom.xml (or project.xml for maven 1.x users) (see docs).

  • Initial Setup

    To initialize maven’s support for updating the eclipse classpath you first need to set the M2_REPO (or MAVEN_REPO for 1.x) classpath variable in the Eclipse workspace by executing the following command in vim:

    maven 2.x:

    :MvnRepo

    maven 1.x:

    :MavenRepo

  • Updating your .classpath

    Once you have performed the initial setup, updating the Eclipse .classpath file is as easy as executing the following at a command line:

    maven 2.x:

    mvn eclipse:eclipse

    maven 1.x:

    maven eclipse

    or in Vim:

    maven 2.x:

    :Mvn eclipse:eclipse

    maven 1.x:

    :Maven eclipse

In your case, every team member should follow this procedure every time he/she wants to be up to date with the dependencies each other has updated in the pom.xml.

Additional readings:

Additional Notes:

Using Gradle you can do it like this:

buildscript {
    // ...
    repositories {
        mavenLocal()      // this uses your local maven repository
        // mavenCentral() // this uses maven central repository
        // maven { url "<some-additional-url-here>" }
    }
    dependencies {
        // ...
    }
}
lealceldeiro
  • 14,342
  • 6
  • 49
  • 80
  • 1
    This worked for me, all I did was run `mvn eclipse:eclipse` in the project and it generated a some directories in the .classpath file like "M2_REPO/org/springframework/security/spring-security-crypto/5.1.0.RELEASE/spring-security-crypto-5.1.0.RELEASE.jar". It cleared all my other configurations but I just had to add back my custom jars to the build path – chinloyal Oct 10 '18 at 19:34