如何解决AWS AMI环境Maven部署构件到Artifactory的http-blocker报错
问题描述
背景
Maven-Server是一台AWS AMI实例,Artifactory运行在另一台AWS AMI实例上,需要将Maven-Server上构建的Maven构件部署到Artifactory实例。
现象
部署时触发maven-default-http-blocker(http://0.0.0.0/)规则,无法完成构件部署。
错误栈信息
[INFO] Scanning for projects... [ERROR] [ERROR] Some problems were encountered while processing the POMs: [FATAL] Non-resolvable parent POM for com.example:sprhava:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.5.4 from/to maven-default-http-blocker (http://0.0.0.0/): Blocked mirror for repositories: [central (http://ec2-public-ipaddress:8082/artifactory/maven-libs-release, default, releases), snapshots (http://ec2-public-ipaddress:8082/artifactory/maven-libs-snapshot, default, releases+snapshots)] and 'parent.relativePath' points at no local POM.
现有配置
settings.xml配置
<?xml version="1.0" encoding="UTF-8"?> <settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <servers> <server> <username>admin</username> <password>Helloadmin123</password> <id>central</id> </server> <server> <username>admin</username> <password>Helloadmin123</password> <id>snapshots</id> </server> </servers> <profiles> <profile> <mirrors> <mirror> <id>central</id> <url>http://ec2-public-ipaddress:8082/artifactory/sprhava-libs-release</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors> <mirrors> <mirror> <id>snapshots</id> <url>http://ec2-public-ipaddress:8082/artifactory/sprhava-libs-snapshot</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors> <repositories> <repository> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>sprhava-libs-release</name> <url>http://ec2-public-ipaddress:8082/artifactory/sprhava-libs-release</url> </repository> <repository> <snapshots /> <id>snapshots</id> <name>sprhava-libs-snapshot</name> <url>http://ec2-public-ipaddress:8082/artifactory/sprhava-libs-snapshot</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>sprhava-libs-release</name> <url>http://ec2-public-ipaddress:8082/artifactory/sprhava-libs-release</url> </pluginRepository> <pluginRepository> <snapshots /> <id>snapshots</id> <name>sprhava-libs-snapshot</name> <url>http://ec2-public-ipaddress:8082/artifactory/sprhava-libs-snapshot</url> </pluginRepository> </pluginRepositories> <id>artifactory</id> </profile> </profiles> <activeProfiles> <activeProfile>artifactory</activeProfile> </activeProfile> </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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.5.4</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>maven</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>maven</name> <description>DevOps CI/CD project </description> <properties> <java.version>11</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> <distributionManagement> <repository> <id>central</id> <name>ip-ec2-ipaddress.compute.internal-releases</name> <url>http://ec2-public-ipaddress:8082/artifactory/maven-libs-release</url> </repository> </distributionManagement>
根因与解决方案
核心根因
Maven 3.8.1及以上版本默认内置maven-default-http-blocker规则,自动拦截所有HTTP协议的非安全仓库,本次报错就是因为你的Artifactory仓库使用HTTP协议被拦截。同时你的settings.xml配置存在规范错误,也是配置不生效的原因之一。
解决方案
方案1:关闭HTTP拦截规则(临时调试用)
在settings.xml的根节点下新增mirror配置,覆盖默认拦截规则,同时修正mirror的位置错误:
<!-- 直接放在<settings>根节点下,不要放在profile内部,删除原来profile里重复的<mirrors>节点 --> <mirrors> <mirror> <id>maven-default-http-blocker</id> <mirrorOf>external:http:*</mirrorOf> <url>http://0.0.0.0/</url> <blocked>false</blocked> </mirror> <!-- 你原来的两个自定义mirror配置放在这里 --> </mirrors>
方案2:配置HTTPS(生产环境推荐)
给Artifactory实例配置域名和SSL证书,将所有仓库地址从HTTP修改为HTTPS,从根源符合Maven安全规范。
其他需修正的配置
settings.xml中<mirrors>节点不能放在<profile>内部,必须直接放在<settings>根节点下才能生效- 统一pom.xml的distributionManagement地址和settings.xml的仓库地址,避免路径不一致导致404
- 部署SNAPSHOT版本构件需要在distributionManagement中新增
snapshotRepository节点,否则快照版本无法正常上传
内容的提问来源于stack exchange,提问作者Raghu
相关产品推荐
相关产品推荐

