Search code examples
javamavenmaven-2maven-3maven-plugin

Maven install for jar creation failure


Im am trying to Maven install and create the jar for my project . but i am getting the following error:

 Plugin org.apache.maven.plugins:maven-surefire-plugin:2.19.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-surefire-plugin:jar:2.19.1: Could not transfer artifact org.apache.maven.plugins:maven-surefire-plugin:pom:2.19.1 from/to central (https://repo.maven.apache.org/maven2): repo.maven.apache.org: unknown error: Unknown host repo.maven.apache.org: unknown error -> [Help 1]

Any help appreciated. I have found similar threads but none of them worked. Added the missing plugin like below but still the same issue. Any help is appreciated.

Plug in added:

<plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
        </plugin>
    </plugins>

Thanks in Advance.


Solution

  • As khmarbaise and lexicore have already mentioned you need to configure your proxy for maven. Please confirm that you are on your company's network. If so:

    Find out your proxy

    If your using your company's laptop your browser is probably already configured to use the company proxy. This is a good wikihow article for looking up your proxy settings in different browsers. You want to take not of:

    • Proxy Server Host Name
    • Proxy Server Port
    • Proxy Server Username (if there is one)
    • Proxy Server Password (if there is one)

    If the proxy hasn't been configured in your browser by normal methods, you should get in touch with your IT department and ask them for the proxy server details.

    Configuring your proxy for maven

    Once you have your proxy server settings. Open your ~/.m2/settings.xml file. If it doesn't exist create it. Now fill in the details of your proxy server with the following format:

    <settings>
      <proxies>
       <proxy>
          <id>work-proxy</id>
          <active>true</active>
          <protocol>http</protocol>
          <host>my.proxy.host.name</host>
          <port>proxyport</port>
          <username>proxyuser</username> <!-- Remove this option if there is no user name -->
          <password>somepassword</password> <!-- Remove this option if there is no password -->
        </proxy>
      </proxies>
    </settings>
    

    The official maven docs for this are here.

    Note: If you take your work laptop home and you don't VPN into the company network, you will have to disable this proxy in order for maven to work at home.