原文链接:https://clutcher.github.io/post/hybris/maven_central_repository_http_issue/
2020-02-04 (Last update: 2020-04-30) — Written by Igor Zarvanskyi
Starting from January 15, 2020 maven central repository is not supporting access via http://repo1.maven.org/maven2
due to security reasons. Unfortunately under the hood hybris uses ant-maven-task, which is not maintained since 2011 and has hardcoded link to http version of maven central.
Such situation leads to download errors during hybris ant build in case of missing dependencies
[artifact:mvn] Downloading: org/apache/maven/apache-maven/3.2.5/apache-maven-3.2.5.pom from repository central at http://repo1.maven.org/maven2
[artifact:mvn] Error transferring file: Server returned HTTP response code: 501 for URL: http://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.2.5/apache-maven-3.2.5.pom
[artifact:mvn] [WARNING] Unable to get resource 'org.apache.maven:apache-maven:pom:3.2.5' from repository central (http://repo1.maven.org/maven2): Error transferring file: Server returned HTTP response code: 501 for URL: http://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.2.5/apache-maven-3.2.5.pom
[artifact:mvn] Downloading: org/apache/maven/apache-maven/3.2.5/apache-maven-3.2.5.pom from repository central at http://repo1.maven.org/maven2
[artifact:mvn] Error transferring file: Server returned HTTP response code: 501 for URL: http://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.2.5/apache-maven-3.2.5.pom
[artifact:mvn] [WARNING] Unable to get resource 'org.apache.maven:apache-maven:pom:3.2.5' from repository central (http://repo1.maven.org/maven2): Error transferring file: Server returned HTTP response code: 501 for URL: http://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.2.5/apache-maven-3.2.5.pom
[null] An error has occurred while processing the Maven artifact tasks.
[null] Diagnosis:
[null]
[null] Unable to resolve artifact: Missing:
[null] ----------
[null] 1) org.apache.maven:apache-maven:pom:3.2.5
[null] Path to dependency:
[null] 1) org.apache.maven:super-pom:pom:2.0
[null] 2) org.apache.maven:apache-maven:pom:3.2.5
[null]
[null] ----------
[null] 1 required artifact is missing.
[null]
[null] for artifact:
[null] org.apache.maven:super-pom:pom:2.0
[null]
[null] from the specified remote repositories:
[null] central (http://repo1.maven.org/maven2)
[null]
[null]
BUILD FAILED
/hybris/bin/platform/build.xml:319: The following error occurred while executing this line:
/hybris/bin/platform/resources/ant/mavenTasks.xml:436: The following error occurred while executing this line:
/hybris/bin/platform/resources/ant/util.xml:20: The following error occurred while executing this line:
/hybris/bin/platform/resources/ant/mavenTasks.xml:438: The following error occurred while executing this line:
/hybris/bin/platform/resources/ant/mavenTasks.xml:659: The following error occurred while executing this line:
/hybris/bin/platform/resources/ant/mavenTasks.xml:689: The following error occurred while executing this line:
/hybris/bin/platform/resources/ant/mavenTasks.xml:490: Unable to resolve artifact: Missing:
----------
1) org.apache.maven:apache-maven:pom:3.2.5
Path to dependency:
1) org.apache.maven:super-pom:pom:2.0
2) org.apache.maven:apache-maven:pom:3.2.5
----------
1 required artifact is missing.
for artifact:
org.apache.maven:super-pom:pom:2.0
from the specified remote repositories:
central (http://repo1.maven.org/maven2)
As a possible fix could be added maven mirror to https version for http maven central repository. In AbstractArtifactWithRepositoryTask#getDefaultRemoteRepository
is defined default repository with id central
. So adding settings.xml with mirror entry will fix the issue:
<settings>
<mirrors>
<mirror>
<id>central.mirror</id>
<url>https://repo1.maven.org/maven2/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
</settings>
Copy
Changing of CI/CD pipeline to add maven settings.xml as local users settings looks overcomplicated and would be better to define settings during hybris ant build.
According to AbstractArtifactTask#initSettings
ant-maven-task will lookup settings.xml file in such locations:
-
$USER_HOME/.ant/settings.xml
-
$USER_HOME/.m2/settings.xml
-
$ANT_HOME/etc/settings.xml
For our purposes location 3 looks like best choice. Below is defined macrodef to copy maven settings.xml from hybirs config dir into hybris ant dir and remove it on clean. (Don’t forget to change yourextension
to proper extension name and put settings.xml file in $HYBRIS_CONFIG_DIR/maven/settings.xml
)
<!-- When SAP will fix issue with maven default url both macrodefs and maven settings file could be removed. -->
<macrodef name="yourextension_before_updateMavenDependencies">
<sequential>
<echo message="Add maven settings"/>
<copy file="${HYBRIS_CONFIG_DIR}/maven/settings.xml" todir="${ant.home}/etc" failonerror="false"/>
</sequential>
</macrodef>
<!-- Clean up custom maven settings -->
<macrodef name="yourextension_before_clean">
<sequential>
<delete failonerror="false" file="${ant.home}/etc/settings.xml"/>
</sequential>
</macrodef>
Copy
P.S. Don’t forget to change yourextension
in macrodef definitions to your real extension name.
P.P.S. Hybris 6.6 Patch 22 has bug in build.xml, which doesn’t pass extension name into build callback to bypass that issue could be used such macrodef:
<!-- There is a bug in current hybris version build, which doesn't pass extension name during callback execution.
Macrodef _before_updateMavenDependencies is dirty workaround. When hybris will fix this issue it could be removed
and proper yourextension_before_updateMavenDependencies would be used.
-->
<macrodef name="_before_updateMavenDependencies">
<sequential>
<echo message="Add maven settings"/>
<copy file="${HYBRIS_CONFIG_DIR}/maven/settings.xml" todir="${ant.home}/etc" failonerror="false"/>
</sequential>
</macrodef>