How does Maven2 know where to find plugins?

廉价感情. 提交于 2019-12-06 05:37:04

问题


I'm using Maven2 and I can't seem to find any plugins in my repository. I'm getting errors like

repository metadata for: 'org.apache.maven.plugins' could not be found on repository: myrepo

where myrepo is the name of my repository.

My question is how does Maven know where to find plugins? There's a reference in my error to metadata, what metadata is expected where and what format must it take? I've not had much luck so far looking for documentation...

(I'm not interested in the easy answer to use the central repo, I want to know why myrepo isn't working.)

Thanks!


回答1:


In the root of each artifact (relative path to repository root [groupId]/[artifactId]), Maven expects to find a maven-metadata.xml file. It uses this file to determine the available versions, the latest version, and the released version.

For example common-logging's metadata from repo1 lists all the available versions and tells us the release version is 1.1.1 as of 28th Nov 2008.

<?xml version="1.0" encoding="UTF-8"?><metadata>
  <groupId>commons-logging</groupId>
  <artifactId>commons-logging</artifactId>
  <version>1.1.1</version>
  <versioning>
    <release>1.1.1</release>
    <versions>
      <version>1.0</version>
      <version>1.0.1</version>
      <version>1.0.2</version>
      <version>1.0.3</version>
      <version>1.0.4</version>
      <version>1.1</version>
      <version>1.1.1</version>
    </versions>
    <lastUpdated>20071128191817</lastUpdated>
  </versioning>
</metadata>

Maven will download the metadata for each remote repository to your local repository (with the name maven-metadata-[repo name].xml) so it can check the available versions without having to hit each repository each time. If you want to force Maven to refetch the metadata you can do so with the "-U" switch on the commandline.

If you have your own repository, it needs to publish this kind of metadata so Maven can determine if any of the versions are available is the right one. The simplest way to do this is to use a repository manager like Nexus or Artifactory which will both manage the metadata for you.



来源:https://stackoverflow.com/questions/1158131/how-does-maven2-know-where-to-find-plugins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!