How to set up maven 3 local plugin repository

2020-06-03 06:35发布

I need to have a completely offline maven repository due to some limitations. According to http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException , only <pluginRepositories> are searched for plugins. So I am wondering how to configure maven to look up plugins in a local file system. I tried using "file://" prefix when setting <url> but it doesn't work.

DEBUG] Verifying availability of /home/dsun/.m2/repository/org/apache/karaf/tooling/features-maven-plugin/2.3.0/features-maven-plugin-2.3.0.jar from [central (http://repo1.maven.org/maven2, releases=true, snapshots=false, managed=false)]
[ERROR] Plugin org.apache.karaf.tooling:features-maven-plugin:2.3.0 or one of its dependencies could not be resolved: The repository system is offline but the artifact org.apache.karaf.tooling:features-maven-plugin:jar:2.3.0 is not available in the local repository. -> [Help 1]
org.apache.maven.plugin.PluginResolutionException: Plugin org.apache.karaf.tooling:features-maven-plugin:2.3.0 or one of its dependencies could not be resolved: The repository system is offline but the artifact org.apache.karaf.tooling:features-maven-plugin:jar:2.3.0 is not available in the local repository.

dsun@localhost:> ls /home/dsun/.m2/repository/org/apache/karaf/tooling/features-maven-plugin/2.3.0/features-maven-plugin-2.3.0.jar
/home/dsun/.m2/repository/org/apache/karaf/tooling/features-maven-plugin/2.3.0/features-maven-plugin-2.3.0.jar

The settings.xml

<settings>      
<offline>true</offline>
  <profiles>
  <profile>
    <id>local</id>
    <pluginRepositories>
      <pluginRepository>
      <id>central</id>
      <url>file://${env.HOME}/.m2/repository</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </pluginRepository>
  </pluginRepositories>
   </profile>
 </profiles>
<activeProfiles>
  <activeProfile>local</activeProfile>
</activeProfiles>

<localRepository>${env.HOME}/.m2/repository</localRepository>

3条回答
做自己的国王
2楼-- · 2020-06-03 07:12

Finally, I found the problem, there's a file called _maven.repositories in the plugin directory, after I delete the file, all works well!

More details, see the following links:

查看更多
劳资没心,怎么记你
3楼-- · 2020-06-03 07:26

Since Maven 3.1-alpha-1, the command line option -llr/--legacy-local-repository or the system property -Dmaven.legacyLocalRepo=true should help

查看更多
Bombasti
4楼-- · 2020-06-03 07:29

This problem annoyed me so much that I patched the war plugin to have a disableOverlaying parameter. You may find it here - forked from the original : https://github.com/crowdcode-de/maven-war-plugin

查看更多
登录 后发表回答