I am facing a strange phenomena related to Maven repository resolution (Maven version: 3.8.4) which I am unable to explain. The matter is as follows:
We have a internal Nexus proxy setup for Central Repository. The URL is http://[companyDomain]:8081/repository/maven-central
I am declaring a repository in the pom.xml as follows:
<repository>
<id>nexus-maven-central</id>
<name>Maven Central Repository Internal Proxy</name>
<url>http://[companyDomain]:8081/repository/maven-central</url>
<layout>default</layout>
<snapshots><enabled>true</enabled></snapshots>
<releases><enabled>true</enabled></releases>
</repository>
The effective pom is showing the above repository as the first in the list of repositories and default Maven Central repository (id:central) after that as it should be.
However, when I build the pom, Maven is directly going to the Maven Central repository, not considering the above repository.
Now, when I start a Nexus instance in my local host and change the above URL to:
http://localhost:8081/repository/maven-central
Maven resolves the repository and downloads from the localhost.
Further, when I use the http://[companyDomain]:8081/repository/maven-central
again in the pom and this time configure a mirror in the global setting.xml (I am not using user specific settings)
<mirror>
<id>nexus-maven-central-mirror</id>
<name>Mirror for Maven Central Repository</name>
<url>http://[companyDomain]:8081/repository/maven-central</url>
<mirrorOf>central</mirrorOf>
</mirror>
Maven perfectly resolves the internal proxy repository and downloads artifacts.
As for the environment, I am connecting to the corporate network through a VPN. IP of the internal Nexus server is resolvable when I am connected to the VPN; there are no VPN outages when I am trying the above.
I was expecting Maven to at least try the internal proxy repo when configured with the 'downloading from ...' message, nothing of that nature shows up in the console. It goes directly to Central Repository.
I further tested with the following URLs:
- http://repo1.maven.org/maven2/ ---> Does Not Work
- https://repo1.maven.org/maven2/ ---> Works
While I am aware that Maven does not prefer to download from 'http' and Maven Central explicitly states that it will send error if accessed over http, then the question is why is it downloading from localhost on http and not remote; does Maven have this behaviour of ignoring remote http.
Or are the 'localhost' and remote repos treated differently by Maven. Or are there some other matter I am missing.
I, unfortunately could not unearth much documentation on the above; any help would be appreciated.