12

I need a local repository for my project for a JAR file not available via the Maven Central repository. I install my JAR using mvn install:install-file … as per http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html, using -DlocalRepositoryPath to indicate the path in my Git repository, and using -DcreateChecksum to create checksums.

This installs the JAR, generates a POM, and generates checksums for all the files. But interestingly it also creates a maven-metadata-local.xml file in the groupId directory. From http://maven.apache.org/ref/3.2.5/maven-repository-metadata/ I gather that local is the ID it is giving the local repository.

But in my POM (mvn install:install-file had no way of knowing) I use the ID local-repo for my repository:

<repositories>
  <repository>
    <id>local-repo</id>
    <url>file:///${project.basedir}/repo</url>
  </repository>
</repositories>

Of course I could change my POM to use simply <id>local</id> to match the generated files, but I don't like to do things without understanding why I'm doing it. So maybe someone could tell me:

  • Do I need the maven-metadata-local.xml? Does it serve a purpose?
  • Does the local part need to match the repository ID I use in the POM?
  • Does mvn install:install-file have a parameter to allow me to indicate the ID to use for the local repository (e.g. to generate maven-metadata-local-repo.xml, or must I manually rename the file afterwards?
Garret Wilson
  • 18,219
  • 30
  • 144
  • 272
  • 1
    have a look at this question? https://stackoverflow.com/questions/2229757/maven-add-a-dependency-to-a-jar-by-relative-path – Daniele Jun 11 '18 at 21:22
  • 1
    Does that question say anything about the repository ID? – Garret Wilson Jun 12 '18 at 13:49
  • 3
    I would recommend to install a repository manager and use this....this will solve your problem.. – khmarbaise Jun 15 '18 at 09:24
  • 1
    But who said I even had a problem? I had some questions. And whether I have a problem one of the questions! You evaded the questions altogether. – Garret Wilson Jun 15 '18 at 13:57
  • 1
    @GarretWilson Based on your post you have jar's you are using which are not in Central which you have to install via `mvn install:install-file`...this is an indicator for using a repository (not the only one) and your strange configuration to use a file based repository...and installing files into a git repository... – khmarbaise Jun 19 '18 at 11:49
  • It does nothing to do with `Java`... – Usagi Miyamoto Jun 21 '18 at 14:20

2 Answers2

1

Do I need the maven-metadata-local.xml? Does it serve a purpose?

Depends of what you want to do, I suggest you to read this to understand the role of maven-metadata-local.xml

http://maven.apache.org/ref/3.2.5/maven-repository-metadata/

Does the local part need to match the repository ID I use in the POM?

No, id declared in pom is just for loggin purpose durring maven build, this will you explain the use of id :

https://maven.apache.org/guides/introduction/introduction-to-repositories.html

Does mvn install:install-file have a parameter to allow me to indicate the ID to use for the local repository (e.g. to generate maven-metadata-local-repo.xml, or must I manually rename the file afterwards?

yes according to maven api guide here :

https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

  • Your 3rd answer is wrong. There is ONLY ONE local repo (where dependencies get downloaded from "remote repos"), so there is NO id for selecting a local repo. – jalopaba Jun 21 '18 at 16:43
  • My answer is not about to named the metadata file to use a custom name. But as answer in point 2 the id as only login purpose the repo is unique... – Arnault Le Prévost-Corvellec Jun 23 '18 at 02:59
1

Do I need the maven-metadata-local.xml? Does it serve a purpose?

Yes, you need it.

That is the file created to store the information of the different versions/releases you have installed in that local repo.

For example, I have installed in a local repo:

  • First, the release 0.2.0 of a jar file.
  • Second, the 0.1.0-SNAPSHOT.

The maven-metadata-local.xml gets updated accordingly:

$ ls -l
drwxrwxr-x. 2 4096 Jun 21 16:14 0.1.0-SNAPSHOT
drwxrwxr-x. 2 4096 Jun 21 16:12 0.2.0
-rw-rw-r--. 1 349 Jun 21 16:14 maven-metadata-local.xml
-rw-rw-r--. 1 32 Jun 21 16:14 maven-metadata-local.xml.md5
-rw-rw-r--. 1 40 Jun 21 16:14 maven-metadata-local.xml.sha1

So that:

$ cat maven-metadata-local.xml
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
[...]
  <versioning>
    <release>0.2.0</release>
    <versions>
      <version>0.2.0</version>
      <version>0.1.0-SNAPSHOT</version>
    </versions>
    <lastUpdated>20180621151442</lastUpdated>
  </versioning>
</metadata>

Does the local part need to match the repository ID I use in the POM?

No. It is for logging purposes (of course you need the URL is a valid repo).

Downloading from this-is-my-local-repo: file:///...

Does mvn install:install-file have a parameter to allow me to indicate the ID to use for the local repository (e.g. to generate maven-metadata-local-repo.xml, or must I manually rename the file afterwards?

No, you don't need to rename the file. That "-local" suffix means that the metadata information it has is "local" to that repo.

Just to make this clearer, as explained in http://maven.apache.org/ref/3.5.2/maven-repository-metadata/:

The metadata file name is:

  • maven-metadata.xml in a remote repository,
  • maven-metadata-<repo-id>.xml in a local repository, for metadata from a repository with repo-id identifier.

So when making a "mvn install", on the local repo used (the default one under ./m2/repository folder or the one given in -DlocalRepositoryPath), the file created is maven-metadata-local.xml since it is a LOCAL repository.

Similarly, on your local repo you can see different maven-metadata-<repo-id>.xml so you can see which repo the artifact is from (example from my local repo, where I have a settings.xml identifying central repo, shared release repo, shared snapshots repo, etc...

.m2/repository/org/apache/maven/plugins/maven-install-plugin/maven-metadata-central.xml .m2/repository/[...]/maven-metadata-snapshots.xml

Summing up,

  • There is ONLY ONE local repo, so no ID to select it on "install-file".
  • Repo ID is for the different repos you may have (for example, a repo for releases named "my-releases", another for snapshots named "my snapshots"). That repo-id is used when deploying an artifact to it:

mvn deploy -DaltDeploymentRepository=my-repo::default::file:///home/jalopaba/my-repo

jalopaba
  • 8,039
  • 2
  • 44
  • 57