Search code examples
javamavendependenciesrepositorylocal

maven: how to specify "systemPath" for dependencied installed locally?


I've got one myPackage maven project, compiled and installed to local maven repository under

~/.m2/repository/mygroup/myPackage/1.0-SNAPSHOT/myPackage-1.0-SNAPSHOT.jar

In another maven project, I wish to use it, and in pom.xml I write <dependency> section for it. But I don't know how to write the "systemPath" for this jar:

  1. I cannot use "~" to specify the path, because "~" is a *nix shell extention, java/maven cannot recognize it.

  2. I cannot hard code like

    /home/myself/.m2/...
    

    It's not portable.

  3. I cannot use ${project.basedir} because these 2 maven projects are under different folders. But I guess there should be some other maven environment variables that could indicate "home directory"?

All I wish to do is to get this "systemPath" done.

---------------Problem solved by using another project as dependency------------

<systemPath>${project.basedir}/../myPackage/pom.xml</systemPath>

That works!


Solution

  • A system path is required when the library that your project depends on is not in the maven local repository.

    As a rule of thumb, this approach is indeed not portable at all and should be avoided for real projects.

    Now, the dependency is in local repository if:

    • It was downloaded from some remote repository (usually)

    • You've installed it locally (in this case its in your local repository but might not be in your team-mate repo)

    In order to install the dependency into the local repo consider using: mvn install:install-file+ parameters as written here

    But from your question, it looks like the file is already there... Anyway once the file is in the local repository you can just define a "regular" dependency (group, artifact, version) and Maven will pick it, no need to fiddle with system Path in this case.