我在 settings.xml 和 pom.xml 中有一个像这样的镜像
设置.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)
- 我试图删除本地仓库或
mvn clean compile -U
下的所有文件夹
- 我用 settings.xml 和 pom.xml 尝试了 grep "repo.spring.io"但一无所获
- 只使用对我有用的单一存储库。
像这样:
<mirror>
<id>my-id</id>
<mirrorOf>*</mirrorOf>
<name>any name</name>
<url>http://anyHost:2227/repository/maven-public</url>
</mirror>
我怎么知道maven为什么要从spring repo下载这个依赖?
最佳答案
使用存储库管理器的正确 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 存储库)中定义的请求重定向到您的内部存储库管理器。
关于java - 为什么maven从spring repo下载jar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52363359/