Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting local repository ID when installing POMs

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?
like image 601
Garret Wilson Avatar asked Jun 11 '18 20:06

Garret Wilson


People also ask

How to change Maven local repository location?

After you have downloaded the maven, follow given simple steps to change maven local repository location to some other path. Navigate to path {M2_HOME}\conf\ where M2_HOME is maven installation folder. Open file settings.xml in edit mode in some text editor. Update the desired path in value of this tag. Save the file.

How do I change the local repository path in each IDE?

Each IDE has a separate process to change the local repository path and that you can read its official documentation. For example in Eclipse and STS ( Spring Tools Suite ), we can change the local repository path in the following location: Windows -> Pfreferences -> Maven -> User Settings

Can I move JAR files and Pom files to another repository?

Note that if there are existing jar files and pom files stored in the previous local repository location, they will not be moved. We need to move them or remove them manually. 3.

How to disable all repositories in the local repository server?

Disable all current repositories in the Local Repository server by running disable-all-repos.sh attachement on the client server. 2. Create a .repo file that will be added to the /etc/yum.repos.d directory on every server using the repositories.


2 Answers

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

like image 114
Arnault Le Prévost-Corvellec Avatar answered Sep 17 '22 23:09

Arnault Le Prévost-Corvellec


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

like image 28
jalopaba Avatar answered Sep 21 '22 23:09

jalopaba