Keywords: Maven | HTTPS | Dependency Resolution | 501 Error | Repository Configuration
Abstract: This paper provides an in-depth analysis of the 501 HTTPS Required error encountered during Maven builds, detailing the background of Maven Central's mandatory HTTPS access requirement effective January 15, 2020. By comparing default configuration differences across Maven versions, it offers two primary solutions: upgrading Maven versions and manually configuring HTTPS repositories. The article includes practical code examples demonstrating correct repository address configuration in pom.xml files and discusses considerations for handling this issue in Jenkins continuous integration environments, helping developers comprehensively understand and resolve this common build failure.
Problem Background and Error Analysis
In recent years, with increasing cybersecurity requirements, major software repositories have strengthened their security protocols. Maven Central, as the primary dependency repository in the Java ecosystem, officially discontinued support for HTTP protocol on January 15, 2020, mandating that all access must be through encrypted HTTPS transmission. This policy change has caused numerous build tasks using older Maven versions or explicitly configured HTTP repository addresses to fail.
From a technical perspective, the 501 error code indicates that the server does not support the operation requested by the client. When Maven attempts to access http://repo.maven.apache.org/maven2 via HTTP protocol, the server returns a "HTTPS Required" response, explicitly indicating that encrypted HTTPS connections must be used. This security policy upgrade is part of an industry trend aimed at preventing man-in-the-middle attacks and data theft.
Root Cause Investigation
The security upgrade of Maven Central repository was not a sudden event. As early as the Maven 3.2.3 release in 2014, the Apache Maven project had already migrated the default central repository address from HTTP to HTTPS. This change is documented in the official release notes, reflecting the project maintainers' forward-looking consideration of security.
However, many projects remain affected due to the following reasons: First, some teams use Maven versions lower than 3.2.3, which default to HTTP protocol; Second, certain projects have explicitly configured HTTP repository addresses in their pom.xml or settings.xml files; Finally, some third-party plugins or custom configurations may override the default repository settings.
This issue is particularly prominent in continuous integration environments like Jenkins, because build servers typically run fixed configurations that are not easily updated in a timely manner. The failure to resolve dependencies for plugins such as org.apache.maven.wagon:wagon-ssh:2.1 and org.apache.maven.plugins:maven-clean-plugin:2.4.1 mentioned in the error messages is precisely due to the mismatch in repository access protocols.
Detailed Solution Approaches
Solution One: Upgrade Maven Version
The most direct solution is to upgrade to Maven 3.2.3 or later. Starting from this version, Maven defaults to using https://repo.maven.apache.org/maven2 as the central repository address. The upgrade process is relatively straightforward:
- Download the latest Maven binary package from the Apache official website
- Extract it to an appropriate directory
- Update the
MAVEN_HOMEorPATHsettings in environment variables - Update Maven Home configuration in IDEs (such as NetBeans)
To verify whether the upgrade was successful, execute mvn --version in the command line and confirm that the version number meets requirements. For Jenkins environments, the Maven installation path needs to be updated in the global tool configuration.
Solution Two: Manual HTTPS Repository Configuration
If immediate Maven version upgrade is not feasible for certain reasons, HTTPS repository addresses can be explicitly configured in the project's pom.xml. This approach is suitable for scenarios requiring compatibility with specific Maven versions.
The following is a complete example of configuring HTTPS repositories in pom.xml:
<project>
<!-- Other configuration items -->
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>This configuration explicitly specifies that both plugin repositories and regular dependency repositories use HTTPS protocol. The <snapshots><enabled>false</enabled></snapshots> element indicates that snapshot versions are not enabled, while <releases><updatePolicy>never</updatePolicy></releases> sets the update policy for release versions.
Technical Implementation Details
Understanding Maven's repository resolution mechanism is crucial for completely resolving this issue. Maven resolves dependencies in the following order: first checking the local repository, then performing remote lookups according to the repository sequence configured in pom.xml, and finally falling back to the default central repository.
When multiple repositories are configured, Maven attempts them sequentially in the configured order until the required dependency is found. This mechanism allows developers to flexibly combine public and private repositories but also increases configuration complexity.
Regarding HTTPS configuration, modern Java runtime environments typically have built-in support for TLS protocol. However, if certificate verification issues arise, additional configuration of trust stores or updates to Java security policies may be necessary. This situation is more common behind corporate firewalls or when using private repositories with self-signed certificates.
Best Practice Recommendations
Based on practical project experience, we recommend adopting the following best practices to avoid similar issues:
- Regularly update Maven versions to maintain synchronization with the latest security standards
- Explicitly specify repository protocols during project initialization to avoid relying on default configurations
- Establish unified build environment standards to ensure consistency across development, testing, and production environments
- Include dependency resolution health checks in continuous integration pipelines
- For enterprise applications, consider setting up mirror repositories or proxy servers
By following these practices, not only can current 501 error issues be resolved, but a solid foundation can also be laid for future project maintenance. Security protocol upgrades are an ongoing process, and keeping technology stacks updated in a timely manner is an essential capability for every development team.