为什么maven从spring repo下载jar?

时间:2018-09-17 08:10:18

标签: java maven spring-boot

我在settings.xml和pom.xml中有这样的镜像

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>

但是当我尝试编译我的项目时,出现此错误:

Could not find artifact com.my.package:httpclient-starter:jar:1.0.0-SNAPSHOT
in spring-snapshot (https://repo.spring.io/snapshot)
  1. 我试图删除本地存储库或mvn clean compile -U下的所有文件夹
  2. 我用settings.xml和pom.xml尝试了grep“ repo.spring.io”
  3. 仅对我使用单个仓库。

赞:

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

我怎么知道为什么Maven从Spring Repo下载了这个依赖项?

4 个答案:

答案 0 :(得分:1)

使用存储库管理器的正确settings.xml设置应如下所示:

<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>

这将正确地将您自己或其他pom(例如spring-boot仓库)中定义的所有请求重定向到内部存储库管理器。

答案 1 :(得分:1)

让我们从从Spring的快照存储库下载Maven的部分开始。从您向我们展示的问题来看,至少不清楚(如果不存在)您在项目中定义了任何快照存储库。因为这是一个Spring Boot项目,所以它将通过父项目(..repo.spring.io..)为您设置一个。 这就是为什么您的项目可以访问此特定服务器的原因。

您尝试下载您可能自己放到一个连结的罐子,对不对?该版本为<sth>-SNAPSHOT,使Maven尝试从某些快照服务器获取。

您的镜子必须是mirrorOf的中央存储库,我只是假设您的jar不在其中,而是在镜子中。

我的想法是像这样将镜像设置为项目pom.xml中的存储库

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

答案 2 :(得分:0)

在repo.spring.io中没有看到这个jar“ httpclient-starter:jar:1.0.0-SNAPSHOT ”。

1) 尝试在浏览器中打开 repo.spring.io 。然后检查是否存在相应的jar,并在settings.xml配置中检查代理设置。

https://repo.spring.io/snapshot

Maven Proxy settings

enter image description here

2) com.my.package:httpclient-starter:jar:1.0.0-SNAPSHOT(如果存在),然后从.m2存储库中手动删除

3)mvn全新安装。

4)如图所示,检查您的RepositoryId和存储库名称。

enter image description here

答案 3 :(得分:0)

您可以使用命令maven install将jar httpclient-starter:jar:1.0.0-SNAPSHOT 安装到本地Maven存储库中