IntelliJ / Maven repo issue

Viewed 3817

I am getting really up the walls with this problem, it's my second day trying to fix it. I tried all sources available on the web (at east what I could find)

I am working with Spring MVC and trying to start new Maven project. What's happening is that the project built from templates and here is the error I am getting.

Downloading:

    https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-archetype-plugin/maven-metadata.xml
[WARNING] Could not transfer metadata org.apache.maven.plugins:maven-archetype-plugin/maven-metadata.xml from/to central (https://repo.maven.apache.org/maven2): sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.224 s
[INFO] Finished at: 2018-08-28T11:52:04+01:00
[INFO] Final Memory: 7M/30M
[INFO] ------------------------------------------------------------------------
[ERROR] Plugin org.apache.maven.plugins:maven-archetype-plugin:RELEASE or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-archetype-plugin:jar:RELEASE: Failed to resolve version for org.apache.maven.plugins:maven-archetype-plugin:jar:RELEASE: Could not find metadata org.apache.maven.plugins:maven-archetype-plugin/maven-metadata.xml in local (C:\Users\pgorski\.m2\repository) -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:

When I build new project without using archetypes, maven is simply not working - and giving following errors:

1: When I check Maven repos, I can see an error with repo.aven.apache.org/maven2 with: java.lang.RuntimeException: java.io.IOException: Transfer for nexus-maven-repository-index.properties failed.

2: When I check Maven projct details, plugins and dependencies are with red under-line.

Here is the output of mvn --debug:

[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
org.apache.maven.lifecycle.NoGoalSpecifiedException: No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy.
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:97)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:954)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoGoalSpecifiedException

Please help

2 Answers

Based on the answers supplied in the comments of the original post, I have reached the conclusion that your company uses a proxy to intercept network traffic. Essentially, it dynamically adds a company-specific certificate to the top of the certification path of all the HTTPS sites you access.

To trust your company-specific certificate in a Java application, you must add it to the java keystore used by that application. In the case of Intellij IDEA, which comes with its own JRE, the steps are the following:

  1. In your browser go to https://www.google.com or any other https site. Click on the lock icon left of the address bar and follow the UI to get info about the certification path. In Chrome, you can view this in the "Certification Path" tab of the dialog that opens when you click "Certificate" after clicking the lock icon.

  2. Click on the top most certificate in the hierarchy (the one with your company's name) and click View Certificate. Click the details tab and then Copy To File. Follow the little wizard to export a .cer Base64 encoded file; let's name it Company. Note that these are Chrome-specific instructions, but there are similar steps for other browsers.

  3. Go to your Intellij IDEA installation folder, subfolder /jre64/bin (or /jre32/bin) and copy Company.cer there.

  4. Open a cmd or PowerShell in the bin folder where you copied the certificate (you can shift right click on an empty space in explorer and the Windows context menu will give you an option for this). Run the following command:

    keytool.exe -keystore ..\lib\security\cacerts -importcert -alias Company -file Company.cer

    When prompted for the password use changeit which is the default keystore password. Also type yes when prompted to confirm the addition of the Company certificate.

  5. Restart Intellij IDEA and retry the action that was giving the initial error.

Okay - it's working now :) Here is the solution: Based on guide from Andrei Pietrusel (big big thanks) I applied the same steps to all security pathes for Java so: IntelliJ JRE, Java JRE's/JDK. I restarted IDE and rebooted the PC and then it finally worked ! 2 days of my life but hell it was worth it :)

One more time, many thanks Andrei !

@Edit: I used portacle for managing certs.

Related