https://my.oschina.net/cjun/blog/881766?utm_medium=referral
https://www.cnblogs.com/huige-you/p/4216353.html
maven报错:Return code is: 501 , ReasonPhrase:HTTPS Required
https://www.cnblogs.com/flashfish/p/12202305.html
自2020年1月15日起,中央存储库不再支持通过纯HTTP进行的不安全通信,并且要求对存储库的所有请求都通过HTTPS进行加密。
于是我们在构建过程中所依赖的settings文件中,加入了一以下配置:
1 2 3 4 5 6 |
|
但是问题依然没有解决,接着报错,错误如下:
Could not transfer artifact com.ipower365.boss:nacha:pom:1.0.1 from/to central (https://repo1.maven.org/maven2/):Received fatal alert: protocol_version -> [Help 1]
这个是在使用https协议请求中央仓库时,需要指定协议版本,然后在构建时,加入了如下参数,参考链接如下:
1 |
|
然后再次构建时,就通过请求了!
原因:我们Java环境用的是7和8两种,而我们的mvn版本用的是3.5.x。
所以,在JAVA8环境使用mvn打包时,不需要指定以上参数,但是使用JAVA7环境的时候,则会出现以上报错。后面会考虑更新下mvn的版本及统一JAVA环境
==========================
一、先搞清楚mirrors,mirror,mirrorOf 简单点来说,repository就是个仓库。maven里有两种仓库,本地仓库和远程仓库。远程仓库相当于公共的仓库,大家都能看到。本地仓库是你本地的一个山寨版,只有你看的到,主要起缓存作用。当你向仓库请求插件或依赖的时候,会先检查本地仓库里是否有。如果有则直接返回,否则会向远程仓库请求,并做缓存。你也可以把你做的东西上传到本地仓库给你本地自己用,或上传到远程仓库,供大家使用。远程仓库可以在工程的pom.xml文件里通过repositories、repository指定。如果没指定,就会去maven的安装目录找setting.xml的mirror、mirrorOf,如果没有设置,默认就会把下面这地方做远程仓库,即默认会到http://repo1.maven.org/maven2这个地方去请求插件和依赖包。
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Maven Repository Switchboard</name>
<url>http://repo1.maven.org/maven2</url>
</repository>
本地仓库默认在你本地的用户目录下的.m2/repository目录下。
mirror就是镜像,主要提供一个方便地切换远程仓库地址的途径。比如,上班的时候在公司,用电信的网络,连的是电信的仓库。回到家后,是网通的网络,我想连网通的仓库,就可以通过mirror配置,统一把我工程里的仓库地址都改成联通的,而不用到具体工程配置文件里一个一个地改地址。 mirror的配置在settings.xml里。如:
<mirrors>
<mirror>
<id>UK</id>
<name>UK Central</name>
<url>http://uk.maven.org/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
这样的话,就会给上面id为central的远程仓库做了个镜像。以后向central这个仓库发的请求都会发到http://uk.maven.org/maven2而不是http://repo1.maven.org/maven2了。<mirrorOf>central</mirrorOf>里是要替代的仓库的id,这里就是会代替central的。如果填*,就会替代所有仓库。
二、经典示例如下:
<servers>
<server>
<id>tomcat7</id>
<username>tomcat</username>
<password>tomcat</password>
</server>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin123</password>
<!--<password>123456</password>-->
</server>
</servers>
<mirrors>
<mirror>
<id>public_repo</id>
<mirrorOf>nexus-releases</mirrorOf>
<url>http://192.168.1.21:8081/nexus/content/groups/bigdata/</url>
<!--<url>http://112.74.204.238:8081/nexus/content/groups/public</url> -->
</mirror>
<mirror>
<id>plugin_repo</id>
<mirrorOf>nexus-plugin</mirrorOf>
<url>http://repo.maven.apache.org/maven2</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus-releases</id>
<url>http://nexus-releases</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-plugin</id>
<url>http://plugin_repo</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
activeProfiles中表示id:nexus的profile生效,nexus的profile又定义了2个repository,当id为nexus-releases的repository去下包时会找到mirrors(用mirrorOf中的值去关联),用对应的mirror的中配置的url来代替repository配置的url去下载包,这就是他们对应的关系了activeProfiles---》repository---》mirrors,用mirrors中的url代替repository的url。也可以使用简要配置,直接所有的东西都用私服地址来下载,那么mirrorOf应该配置成*(代表替换所有的)或者maven默认的repository地址(代表替换默认的)
<mirror>
<id>public_repo</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.1.21:8081/nexus/content/groups/bigdata/</url>
</mirror>
私有仓库SNAPSHOT和release都可以 nexus3.8
上传快照类型:
mvn -s /var/jenkins_home/mvn/conf/settings.xml deploy:deploy-file -DgeneratePom=true -DgroupId=com.jettech.infrastructure -DartifactId=jettech-encry-license -Dversion=1.0.0.RELEASE -Dpackaging=jar -Dfile=licensectl-0.0.1-SNAPSHOT.jar -DpomFile=pom.xml -DrepositoryId=thirdparty -Durl=http://172.16.10.1:8082/repository/thirdparty-snapshot/
下载不下来 所以要加下面文件最后那部分
测试下载
mvn -s settings.xml -f pom.xml dependency:copy-dependencies
[root@localhost mavne-download]# cat pom.xml
<?xml version="1.0"?>
<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>temp.download</groupId>
<artifactId>temp-download</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- 需要下载什么jar包 添加相应依赖 其余部分无需在意-->
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
<version>2.2.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
[root@localhost mavne-download]# cat 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>/root/maven/repo</localRepository>
<servers>
<server>
<id>thirdparty</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>thirdparty-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<mirrors>
<mirror>
<id>thirdparty</id>
<name>maven-public</name>
<mirrorOf>*</mirrorOf>
<url>http://172.16.10.1:8082/repository/maven-public/</url>
</mirror>
<mirror>
<id>thirdparty-snapshots</id>
<name>maven-public</name>
<mirrorOf>*</mirrorOf>
<url>http://172.16.10.1:8082/repository/maven-public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>jettech-repo</id>
<repositories>
<repository>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
<id>maven-public</id>
<name>Maven Repository Switchboard</name>
<url>http://jettech-public</url>
<layout>default</layout>
<snapshotPolicy>always</snapshotPolicy>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>jettech-repo</activeProfile>
</activeProfiles>
</settings>