How to change maven's Remote Repository URL in the NetBeans IDE (from http to https)?
Asked Answered
H

3

11

When trying to run a NetBeans project, I get the following error message:

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-test) on project MyNetBeansProject: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test failed: Plugin org.apache.maven.plugins:maven-surefire-plugin:2.10 or one of its dependencies could not be resolved: Failed to collect dependencies for org.apache.maven.plugins:maven-surefire-plugin:jar:2.10 (): Failed to read artifact descriptor for org.apache.maven.surefire:surefire-booter:jar:2.10: Could not transfer artifact org.apache.maven.surefire:surefire-booter:pom:2.10 from/to central (http://repo.maven.apache.org/maven2): Failed to transfer file: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-booter/2.10/surefire-booter-2.10.pom. Return code is: 501 , ReasonPhrase:HTTPS Required. -> [Help 1]

The following part of the error message is the most important one:

Failed to transfer file: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-booter/2.10/surefire-booter-2.10.pom. Return code is: 501 , ReasonPhrase:HTTPS Required.

Services -> Maven Repositories -> Central Repository -> right mouse click on "Central Repository" gives the following information:

enter image description here

As one can see, the Remote Repository URL is "http://repo.maven.apache.org/maven2/". I think it should instead be "https://repo.maven.apache.org/maven2/". However, the problem is that I can't seem to change the Remote Repository URL.

Does anybody know how to change maven's Remote Repository URL in the NetBeans IDE?


UPDATE:

Under NetBeans -> Preferences one can see that the maven version used by my NetBeans IDE is Version 3.0.5:

enter image description here

Humanitarian answered 2/2, 2020 at 22:3 Comment(7)
Have you tried the button on the right side with those three dots?Masaryk
@Masaryk yes I did ... clicking on it just shows me the value in a separate window . but I still can't change the valueHumanitarian
Have you tried editing settings.xml on .m2 directory and restart netbeans?Catcher
Ok. Than you should check which Maven version you are using? I strong recommend to use the most recent version 3.6.3 ...furthermore check the settings.xml as mentioned by @CatcherMasaryk
@Masaryk the maven version used by my netbeans IDE is 3.0.5 (see updated post) ... I don't know how I can change the maven version, though. It seems to be fixed by NetBeans. I don't have a setting.xml file in folder .m2.Humanitarian
I think about should check which Netbeans version you are using? Current Maven version is 3.6.3....Masaryk
The Netbeans version I'm using is 8.2Humanitarian
S
15

I think you have three options.

1. Migrate to 11.0

You can migrate to Netbeans 11.0 LTS (or 11.2), it uses a built-in Maven 3.3.9 version. It already uses https.

enter image description here

2. Install standalone Apache Maven

You can stay with Netbeans 8.2 but download standalone apache maven, install it to your system and set the path to the new maven home directory in Options -> Java -> Maven -> Maven Home.

You need just:

  1. Download apache-maven-3.6.3-bin.zip (or apache-maven-3.6.3-bin.tar.gz) from Apache
  2. Unzip it to any directory. It will be the Maven home.
  3. Set the Maven home directory in NetBeans to the directory where you have extracted zip file.
  4. Ensure than you have set JAVA_HOME in your environment variables

Instructions how to install standalone version here.

If you set the Maven Home in NetBeans correctly it will show you updated version: enter image description here

3. Quick and not recommended

Just add repositories into your pom.xml with https (for example like that)

<repositories>
        <repository>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <id>central</id>
            <name>Central Repository</name>
            <url>https://repo.maven.apache.org/maven2</url>
        </repository>
    </repositories>
<pluginRepositories>
    <pluginRepository>
        <releases>
            <updatePolicy>never</updatePolicy>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <id>central</id>
        <name>Central Repository</name>
        <url>https://repo.maven.apache.org/maven2</url>
    </pluginRepository>
</pluginRepositories>

Maven Central Migrated to https

The problem comes from this:

As of January 15, 2020, The Central Repository no longer supports insecure communication over HTTP and requires that all requests to the repository are encrypted over HTTPS.

Here is the relevant improvement that was resolved and relevant changes.

Souvenir answered 3/2, 2020 at 17:57 Comment(1)
Thank you for your solution. After downloading Netbeans 11.2 I was able to "clean and build" the project. However, running it resulted in another error message: "No suitable Deployment Server is defined for the project or globally", see #60047940 ... do you happen to know the reason for this error message as well?Humanitarian
S
17

Within the Netbeans installation, this worked for me:

Goto Netbeans installation folder > java > maven > conf, and here I updated the settings.xml file using administrative privilege.

as http repo link will not work now, just I created an mirror for central repo that is pre-built with IDE which cannot be changed.

Add this inside mirrors tag of settings.xml

<mirror>
      <id>mirror1</id>
      <mirrorOf>central</mirrorOf>
      <name>mirror1</name>
      <url>https://repo.maven.apache.org/maven2/</url>
</mirror>

after this restart netbeans IDE, and central repository will be overridden with the mirror we specify.

Sweeping answered 7/4, 2020 at 2:37 Comment(2)
What happens if we replace the url with our private repository and maven can not find a dependency? It will search in somewhere else?Backboard
Make sure it has all dependency present, maven will not search anywhere else unless you add where to search for.Sweeping
S
15

I think you have three options.

1. Migrate to 11.0

You can migrate to Netbeans 11.0 LTS (or 11.2), it uses a built-in Maven 3.3.9 version. It already uses https.

enter image description here

2. Install standalone Apache Maven

You can stay with Netbeans 8.2 but download standalone apache maven, install it to your system and set the path to the new maven home directory in Options -> Java -> Maven -> Maven Home.

You need just:

  1. Download apache-maven-3.6.3-bin.zip (or apache-maven-3.6.3-bin.tar.gz) from Apache
  2. Unzip it to any directory. It will be the Maven home.
  3. Set the Maven home directory in NetBeans to the directory where you have extracted zip file.
  4. Ensure than you have set JAVA_HOME in your environment variables

Instructions how to install standalone version here.

If you set the Maven Home in NetBeans correctly it will show you updated version: enter image description here

3. Quick and not recommended

Just add repositories into your pom.xml with https (for example like that)

<repositories>
        <repository>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <id>central</id>
            <name>Central Repository</name>
            <url>https://repo.maven.apache.org/maven2</url>
        </repository>
    </repositories>
<pluginRepositories>
    <pluginRepository>
        <releases>
            <updatePolicy>never</updatePolicy>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <id>central</id>
        <name>Central Repository</name>
        <url>https://repo.maven.apache.org/maven2</url>
    </pluginRepository>
</pluginRepositories>

Maven Central Migrated to https

The problem comes from this:

As of January 15, 2020, The Central Repository no longer supports insecure communication over HTTP and requires that all requests to the repository are encrypted over HTTPS.

Here is the relevant improvement that was resolved and relevant changes.

Souvenir answered 3/2, 2020 at 17:57 Comment(1)
Thank you for your solution. After downloading Netbeans 11.2 I was able to "clean and build" the project. However, running it resulted in another error message: "No suitable Deployment Server is defined for the project or globally", see #60047940 ... do you happen to know the reason for this error message as well?Humanitarian
H
1

Go maven>conf and update settings.xml

<profile>
    <id>maven-https</id>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
    
    
    <repositories> 
        <repository>
            <id>central</id> 
            <url>https://repo1.maven.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
         
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>central</id>
            <url>https://repo1.maven.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>  
</profile>
Heterogamy answered 11/2, 2022 at 17:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.