Maven can't find artifacts in remote file repo

2019-08-23 02:17发布

问题:

Background: I'm working on a maven project in a closed network, which means I can't connect to Maven Central. I have a repository folder containing all the artifacts I should need, including plugins and maven artifacts. Also, I can't use or install Nexus.

Problem: I want to run a Jenkins job using maven 3.6.0 / jdk 1.8.0_162. My settings.xml file is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository>D:\Maven\repository</localRepository>

  <interactiveMode>false</interactiveMode>

  <offline>false</offline>

  <pluginGroups />

  <proxies />

  <servers />

  <mirrors>
    <mirror>
      <id>ExternalRespositoryMirror</id>
      <name>Maven External Repository Mirror</name>
      <url>file://myserver/repository/maven/repository</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>

  <profiles>
    <profile>
      <id>jenkins</id>
      <repositories>
        <repository>
          <id>central</id>
          <name>Maven External Dependencies Repository</name>
          <url>file://myserver/repository/maven/repository</url>
          <layout>default</layout>
          <releases>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
          </snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <name>Maven External Plugins Repository</name>
          <url>file://myserver/repository/maven/repository</url>
          <layout>default</layout>
          <releases>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>

  <activeProfiles>
    <activeProfile>jenkins</activeProfile>
  </activeProfiles>

</settings>

My POM's have no repository section as the jenkins slave should determine where to get those.

When I build, I get the following error though:

[ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Could not find artifact org.apache.maven.plugins:maven-clean-plugin:jar:2.5 in ExternalRespositoryMirror (file://myserver/repository/maven/repository) -> [Help 1]

I can open the file:// url and the artifact "maven-clean-plugin-2.5.jar" is in the folder \maven\repository\org\apache\maven\plugins\maven-clean-plugin\2.5

What could be the reason that maven can't find the artifact? It is present in the local repository (D:\Maven\repository) so it shouldn't actually query the network repo anyway.

回答1:

You might want to simply try installing the jars into a local repository and just skip the remote aspect. Maven will look in the local repository before going remote.

Guide to installing 3rd party JARs

Create a single pom to doing the copying, tie it to the process-resources phase. You can pull them (eg: scp/robocopy/unzip) from a known location (don't check into a VCS; bad practice, wasted space) and install them.

fyi, this is the opposite to what aether-ant Tasks does, which is pull from amaven repository and copy to a target directory, useful for ant builds to use jars from a (nexus) repository, see:

Aether/Ant Tasks

Apache Ant and Eclipse Aether