Why does maven download jar from spring repo?

Viewed 1418

I have a mirror in settings.xml and pom.xml like this

settings.xml

  <?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>${user.home}/.m2/repository</localRepository>

    <pluginGroups>
    </pluginGroups>

    <proxies>
    </proxies>
    <servers>
      <server>
        <id>nexus-release</id>
        <username>username</username>
        <password>password</password>
      </server>

      <server>
        <id>nexus-snapshot</id>
        <username>username</username>
        <password>password</password>
      </server>
    </servers>

    <mirrors>
       <mirror>
        <id>nexus-any</id>
        <mirrorOf>central</mirrorOf>
        <name>Nexus any</name>
        <url>http://anyHost:2227/repository/maven-public</url>
      </mirror>
    </mirrors>
    <profiles>
    </profiles>
  </settings>

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.my.projecy</groupId>
<artifactId>my-project</artifactId>
<packaging>pom</packaging>
<version>1.3.0</version>

<modules>
    <module>my-project-pool</module>
    <module>my-project-business</module>
    <module>my-project-web-deploy</module>
    <module>my-project-task-deploy</module>
    <module>my-project-stats</module>
    <module>my-project-bizlog</module>
</modules>

<name>my-project</name>
<description>Educational Administration Offline System</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.RELEASE</version>
    <relativePath/>
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <mybatis.version>1.3.2</mybatis.version>
    <httpClient.version>4.5.5</httpClient.version>
    <maven.plugins.jar.version>3.1.0</maven.plugins.jar.version>
    <maven.plugins.assembly.version>3.1.0</maven.plugins.assembly.version>
    <offline.api.version>1.3.1-SNAPSHOT</offline.api.version>
    <online.api.version>1.3.0-SNAPSHOT</online.api.version>
    <starter.httpclient.version>1.0.0-SNAPSHOT</starter.httpclient.version>
    <lombok.version>1.16.2</lombok.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>${lombok.version}</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>com.my.projecy.starter</groupId>
        <artifactId>httpclient-starter</artifactId>
        <version>${starter.httpclient.version}</version>
    </dependency>

    <dependency>
        <groupId>com.my.projecy</groupId>
        <artifactId>bluesky-common</artifactId>
        <version>1.1-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>com.my.projecy</groupId>
        <artifactId>ea-api-online</artifactId>
        <version>${online.api.version}</version>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>${mybatis.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>${httpClient.version}</version>
        </dependency>

        <dependency>
            <groupId>com.my.projecy</groupId>
            <artifactId>my-project-pool</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>com.my.projecy</groupId>
            <artifactId>my-project-business</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>com.my.projecy</groupId>
            <artifactId>my-project-web-deploy</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>com.my.projecy</groupId>
            <artifactId>my-project-task-deploy</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>com.my.projecy</groupId>
            <artifactId>ea-api-offline</artifactId>
            <version>${offline.api.version}</version>
        </dependency>

        <dependency>
            <groupId>com.my.projecy</groupId>
            <artifactId>my-project-stats</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>com.my.projecy</groupId>
            <artifactId>my-project-bizlog</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>${maven.plugins.assembly.version}</version>
        </dependency>
    </dependencies>
</dependencyManagement>

But when I try to compile my project, I get this error:

Could not find artifact com.my.package:httpclient-starter:jar:1.0.0-SNAPSHOT
in spring-snapshot (https://repo.spring.io/snapshot)
  1. I tried to delete all folders under local repo or mvn clean compile -U
  2. I tried grep "repo.spring.io" with settings.xml and pom.xml and got nothing
  3. Only use single repo works for me.

Like this:

<mirror>
  <id>my-id</id>
  <mirrorOf>*</mirrorOf>
  <name>any name</name>
  <url>http://anyHost:2227/repository/maven-public</url>
</mirror>     

How can I know why maven downloads this dependency from spring repo?

4 Answers

A correct settings.xml setup for using a repository manager should look like this:

<settings>
  <mirrors>
    <mirror>
      <!--This sends everything else to /public -->
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://localhost:8081/nexus/content/groups/public/</url>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <id>nexus</id>
      <!--Enable snapshots for the built in central repo to direct -->
      <!--all requests to nexus via the mirror -->
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <!--make the profile active all the time -->
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
  <servers>
    <!-- Possible authentications for access to nexus -->
    <server>
      <id>snapshots</id>
      <username>xxx</username>
      <password>xxx</password>
    </server>
    <server>
      <id>releases</id>
      <username>xxx</username>
      <password>xxx</password>
    </server>
  </servers>
</settings>

this will correctly redirect all request which are defined in your own or other pom's (like spring-boot repos) to your internal repository manager.

Let's start with the part of Maven downloading from Spring's snapshot repository. From what you showed us in the question it is at least unclear (if not existent) that you defined any snapshot repository in your project. Because this is a Spring Boot project, it will set you one through the parent project (..repo.spring.io..). This is why your project reaches out to this particular server.

You try to download a jar you probably put to nexus by yourself, right? The version is <sth>-SNAPSHOT that make Maven try to fetch from some snapshot server.

Your mirror is must a mirrorOf the central repository where I just assume your jar does not live but "in" the mirror.

My idea would be to set your mirror as a repository in your project's pom.xml like this

<repositories>
  <repository>
    <id>myInternalRepository</id>
    <url>http://localhost:8081/nexus/content/groups/???</url>
    <snapshots>
      <enabled>true</enabled>
    </snapshots>
</repository>

I didnt see "httpclient-starter:jar:1.0.0-SNAPSHOT" this jar in repo.spring.io.

1) Try to open repo.spring.io on the browser. Then check the respective jar exising in that or not and also check your proxy settings in your settings.xml configuration.

https://repo.spring.io/snapshot

Maven Proxy settings

enter image description here

2) com.my.package:httpclient-starter:jar:1.0.0-SNAPSHOT if exists then delete it manually from .m2 repository

3) mvn clean install.

4) Check your RepositoryId and Repository name as shown in pic.

enter image description here

you can install the jar httpclient-starter:jar:1.0.0-SNAPSHOT into you local maven repository with command maven install

Related