Friday, June 1, 2018

Maven unable to find valid certification path

Here is the most useful command that could help clean up the mess in Maven.
mvn –U clean compile
Unfortunately, that command is giving me a nasty error complaining that Maven was not able to find a valid certificate. WHAT THE HELL?
[ERROR] Plugin org.apache.maven.plugins:maven-compiler-plugin:3.7.0 or one of its dependencies could not be resolved: 
Failed to read artifact descriptor for org.apache.maven.plugins:maven-compiler-plugin:jar:3.7.0: Could not transfer artifact org.apache.maven.plugins:maven-plugins:pom:30 
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 -> [Help 1]
Will this error coming from the network firewall failure? If I read the details closely, this gives me a sense that my PC have not trusted the certificate for the site. In order to proceed the compilation, I must first trust the certificate, but how? I have no idea on dealing with Maven’s security issue during my past working experience. Spending hours on this issue and found this workaround from the Internet. First, follow the following steps to download the certificate and then import the certificate into a self-made keystore:
  1. Use a browser to go to https://repo.maven.apache.org/
  2. Click on lock icon and choose "View Certificate" 
  3. Go to the "Details"
  4. tab and choose "Save to File" Choose type "Base 64 X.509 (.CER)" and save it as mavenCert.cer 
  5. keytool -import -file mavenCert.cer -keystore mavenkeystore 
Once done, compile using following command:
mvn –U clean compile -Djavax.net.ssl.trustStore=mavenkeystore
From now on, whenever I need to download a new artifact from the maven repository or to do a clean build, I am required to use the command mention above instead of mvn –U clean compile.

Reference

No comments: