今天使用jenkins构建时,报以下错误

  [ERROR] Failed to execute goal on project saas20: Could not resolve dependencies for project com.ipower365.saas:saas20:war:0.0.1-SNAPSHOT: Failed to collect dependencies at com.ipower365.saas:messageserviceimpl:jar:0.0.1-SNAPSHOT -> com.ipower365.boss:nacha:jar:1.0.1: Failed to read artifact descriptor for com.ipower365.boss:nacha:jar:1.0.1: Could not transfer artifact com.ipower365.boss:nacha:pom:1.0.1 from/to central (​​http://repo1.maven.org/maven2/):​​​Failed to transfer file:​​http://repo1.maven.org/maven2/com/ipower365/boss/nacha/1.0.1/nacha-1.0.1.pom​​. Return code is: 501 , ReasonPhrase:HTTPS Required. -> [Help 1]

  我们发现,这个依赖的文件在本地仓库是有的,但是在构建过程中,在本地nexus下载完文件后,还是会像中央仓库请求文件下载

    [echoing saas20] Downloading from central: http://repo1.maven.org/maven2/com/ipower365/boss/nacha/1.0.1/nacha-1.0.1.pom

  之后我们根据返回的501错误,去搜索问题,参考链接如下:

  ​​https://stackoverflow.com/questions/59763531/maven-dependencies-are-failing-with-501-error​

关于maven打包时的报错: Return code is: 501 , ReasonPhrase:HTTPS Required._jar

 

 

   上面提示,自2020年1月15日起,中央存储库不再支持通过纯HTTP进行的不安全通信,并且要求对存储库的所有请求都通过HTTPS进行加密。

  于是我们在构建过程中所依赖的settings文件中,加入了一以下配置:

<mirror>
<id>centralid>
<name>Maven Repository Switchboardname>
<url>https://repo1.maven.org/maven2/url>
<mirrorOf>centralmirrorOf>
mirror>

  但是问题依然没有解决,接着报错,错误如下:

    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协议请求中央仓库时,需要指定协议版本,然后在构建时,加入了如下参数,参考链接如下: 

    ​​https://stackoverflow.com/questions/50824789/why-am-i-getting-received-fatal-alert-protocol-version-or-peer-not-authentic​​  

-Dhttps.protocols=TLSv1.2

  然后再次构建时,就通过请求了!

原因:我们Java环境用的是7和8两种,而我们的mvn版本用的是3.5.x。

    所以,在JAVA8环境使用mvn打包时,不需要指定以上参数,但是使用JAVA7环境的时候,则会出现以上报错。后面会考虑更新下mvn的版本及统一JAVA环境