Maven
  1. Maven
  2. MNG-5258

localRepository in settings.xml does not handle ~ as home.dir

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.2.1, 3.0.4
    • Fix Version/s: 3.1.0-alpha-1
    • Component/s: Bootstrap & Build, Settings
    • Labels:
      None
    • Environment:
      Linux (Ubuntu 11.10), Java 6
    • Complexity:
      Intermediate
    • Number of attachments :
      0

      Description

      My provided settings.xml contained a localRepository part with the value ~/.m2/repository and when invoking any maven command, this caused issues.

      Steps to reproduce:

      1 - create a settings.xml with the following content:
      <settings>
      <!-- localRepository

      The path to the local repository maven will use to store artifacts.
      Default: ~/.m2/repository -->
      <localRepository>~/.m2/repository</localRepository>
      </settings>

      2 - run mvn clean in an existing project

      3 - maven will create a ~ directory in the project where it will download all artifacts to.

      Apart from essentially creating a private repository for each project (which can quickly take up way more space than necessary, cause issues about missing artifacts) it may also cause issues if you try to remove it and forget to escape the ; ie if you do rm -rf ~ instead of rm -rf ''.

      I also tested with maven 2.2.1 and that will blow up with errors about not being able to create /.m2/repository/<some path to an artifact>.

      Both 3.0.4 and 2.2.1 were downloaded from maven.apache.org, not installed via apt/dpkg.

        Activity

        Hide
        Robert Balazsi added a comment -

        The problem also persists under Windows, i.e. %HOMEPATH% will not be handled as the user's home directory.

        Show
        Robert Balazsi added a comment - The problem also persists under Windows, i.e. %HOMEPATH% will not be handled as the user's home directory.
        Hide
        Olivier Lamy added a comment -

        try with

        <localRepository>${user.home}/.m2/repository</localRepository>
        

        BTW why define this with the default value ???

        Show
        Olivier Lamy added a comment - try with <localRepository>${user.home}/.m2/repository</localRepository> BTW why define this with the default value ???
        Hide
        Robert Balazsi added a comment -

        It works with $

        {user.home}

        , and it is pointless indeed to define with its default value.
        However, I think it would be nice to support "~" (or %HOMEPATH%) in case somebody wants to create a private repository somewhere in his/her home directory.

        Show
        Robert Balazsi added a comment - It works with $ {user.home} , and it is pointless indeed to define with its default value. However, I think it would be nice to support "~" (or %HOMEPATH%) in case somebody wants to create a private repository somewhere in his/her home directory.
        Hide
        Olivier Lamy added a comment -

        "to create a private repository somewhere in his/her home directory." just use $

        {user.home}

        /foo/maven-rocks-repository

        Show
        Olivier Lamy added a comment - "to create a private repository somewhere in his/her home directory." just use $ {user.home} /foo/maven-rocks-repository
        Hide
        Thomas Zeeman added a comment -

        As mentioned in the original report, the settings.xml was provided to me. I've now traced the source and it was an adapted version from the one supplied in the conf directory of the maven binary distribution. The <localRepository> part was copied from there and the value changed from /path/to/local/repo to what was in the comment; apparently in the expectation that the value in the comment works as advertised.

        As to the usefulness of having a value of ~/.m2/repository, I agree it is rather low and I've since removed this entry from my settings.xml. But it took me some time to figure out what was going wrong especially given the expectations one has about ~ on a *nix system and the comment in the maven provided example settings.xml. (Not to mention that a ~ directory does not show in a typical ls output, my IDE populated the 'real' ~/.m2/repository and any cli executed maven commands were only occasionally failing or downloading artifacts again.)

        So if you consider this 'not a bug', then at least update the comment in the apache-maven/src/conf/settings.xml to say $

        {user.home}

        /.m2/repository instead of ~/.m2/repository which obviously does not work as expected and advertised. Optionally consider making v3 behave like v2 and simply ignore the ~ in the value for the localRepository.
        That should hopefully save others who want to relocate the repo to somewhere else in their home dir some time in figuring out why it does not work.

        Show
        Thomas Zeeman added a comment - As mentioned in the original report, the settings.xml was provided to me. I've now traced the source and it was an adapted version from the one supplied in the conf directory of the maven binary distribution. The <localRepository> part was copied from there and the value changed from /path/to/local/repo to what was in the comment; apparently in the expectation that the value in the comment works as advertised. As to the usefulness of having a value of ~/.m2/repository, I agree it is rather low and I've since removed this entry from my settings.xml. But it took me some time to figure out what was going wrong especially given the expectations one has about ~ on a *nix system and the comment in the maven provided example settings.xml. (Not to mention that a ~ directory does not show in a typical ls output, my IDE populated the 'real' ~/.m2/repository and any cli executed maven commands were only occasionally failing or downloading artifacts again.) So if you consider this 'not a bug', then at least update the comment in the apache-maven/src/conf/settings.xml to say $ {user.home} /.m2/repository instead of ~/.m2/repository which obviously does not work as expected and advertised. Optionally consider making v3 behave like v2 and simply ignore the ~ in the value for the localRepository. That should hopefully save others who want to relocate the repo to somewhere else in their home dir some time in figuring out why it does not work.
        Hide
        Robert Scholte added a comment -

        Fixed in rev. 1300694

        Show
        Robert Scholte added a comment - Fixed in rev. 1300694

          People

          • Assignee:
            Robert Scholte
            Reporter:
            Thomas Zeeman
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: