Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Maven to use HTTPS when connecting to repo.maven.apache.org

Tags:

https

maven

I would like to secure the connection to repo.maven.apache.org when resolving dependencies (I wolud like to secure all connections made by Maven actually), but I'm not used to Maven configuration... My user settings.xml contains the following repositories and pluginRepositories sections:

<profiles>
    <profile>
        <id>main</id>
        <repositories>
            <repository>
                <id>central</id>
                <url>https://repo.maven.apache.org</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
            </repository>
        </repositories>

        <pluginRepositories>
            <pluginRepository>
                <id>central</id>
                <url>https://repo.maven.apache.org</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
            </pluginRepository>
        </pluginRepositories>
    </profile>
</profiles>

However Maven is unable to resolve dependencies with that setup.

like image 827
Guillermo López Alejos Avatar asked Mar 08 '15 13:03

Guillermo López Alejos


People also ask

Does Maven use HTTP?

By default, Maven uses the java. net. URLConnection ( HttpURLConnection ) classes provided with the JDK to access repositories that use the HTTP/HTTPs protocols.

Where we can configure Maven remote repository URL?

Maven central repository is located at http://repo.maven.apache.org/maven2/. Whenever you run build job, maven first try to find dependency from local repository. If it is not there, then, by default, maven will trigger the download from this central repository location.


1 Answers

Open the file $MAVEN_HOME/conf/settings.xml (where $MAVEN_HOME is the folder in which Maven has been installed) in a text editor. Then, add the following to the <mirrors>...</mirrors> section in this file:

<mirror>
  <id>central-secure</id>
  <url>https://repo.maven.apache.org/maven2</url>
  <mirrorOf>central</mirrorOf>
</mirror>
like image 132
manish Avatar answered Oct 29 '22 12:10

manish