3 minute read

Don’t promis when you are hapy. Don’t reply when you’re angry and don’t decide when you’re sad

Background & symptoms

One of most found error is Failed to execute goal on project xxx when you run

mvn install

For example, below is error screenshot and mesage details

Please be advised the error wording Failed to execute goal on project abc-project-client: Could not resolve dependencies for project com.abc.dmy.

[ERROR] Failed to execute goal on project abc-project-client: Could not resolve dependencies for project com.abc.dmy.client:abc-client-code:jar:2.0.0-SNAPSHOT: Failed to collect dep
endencies at com.abc.client:abc-client-test:jar:2.0.0-SNAPSHOT -> com.abc.dmy.client:dmy-client-common:jar:2.0.0-SNAPSHOT: Failed to read artifact descriptor for com.abc.dmy.
client:dmy-client-common:jar:2.0.0-SNAPSHOT: Could not transfer artifact io.micrometer:micrometer-bom:pom:1.3.1 from/to central (https://repo.maven.apache.org/maven2): transfer failed for ht
tps://repo.maven.apache.org/maven2/io/micrometer/micrometer-bom/1.3.1/micrometer-bom-1.3.1.pom, proxy: ProxyInfo{host='abc-proxy.prod.brx.abc.com/', userName='null', port=8080, type='h
ttps', nonProxyHosts='null'}: No such host is known (abc-proxy.prod.brx.abc.com/) -> [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:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

Troubleshooting

What done is done, we are facing errors, what shall we do? To debug and fix an issue, firstly we’d stay calm and keep on debuging.

As you already know, if you’d like to know rootcause of error, firslty to drilldown to get more error details. You can run following command to output verbose logs

mvn -X install -l mvnOutput.log

Explained

-X indicate this is for debug -l mvnOutput.log denote output of this maven command to saved in file called mvnOutput.log

Here are more details extract in above output, check the words No such host is known


Caused by: java.net.UnknownHostException: No such host is known (dmy-proxy.prod.abc.com/)
    at java.net.Inet6AddressImpl.lookupAllHostAddr (Native Method)
    at java.net.InetAddress$PlatformNameService.lookupAllHostAddr (InetAddress.java:929)
    at java.net.InetAddress.getAddressesFromNameService (InetAddress.java:1519)
    at java.net.InetAddress$NameServiceAddresses.get (InetAddress.java:848)
    at java.net.InetAddress.getAllByName0 (InetAddress.java:1509)
    at java.net.InetAddress.getAllByName (InetAddress.java:1368)
    at java.net.InetAddress.getAllByName (InetAddress.java:1302)
    at org.apache.maven.wagon.providers.http.httpclient.impl.conn.SystemDefaultDnsResolver.resolve (SystemDefaultDnsResolver.java:45)
    at org.apache.maven.wagon.providers.http.httpclient.impl.conn.DefaultHttpClientConnectionOperator.connect (DefaultHttpClientConnectionOperator.java:112)
    at org.apache.maven.wagon.providers.http.httpclient.impl.conn.PoolingHttpClientConnectionManager.connect (PoolingHttpClientConnectionManager.java:376)
    at org.apache.maven.wagon.providers.http.httpclient.impl.execchain.MainClientExec.establishRoute (MainClientExec.java:401)
    at org.apache.maven.wagon.providers.http.httpclient.impl.execchain.MainClientExec.execute (MainClientExec.java:236)
    at org.apache.maven.wagon.providers.http.httpclient.impl.execchain.ProtocolExec.execute (ProtocolExec.java:186)
    at org.apache.maven.wagon.providers.http.httpclient.impl.execchain.RetryExec.execute (RetryExec.java:89)
    at org.apache.maven.wagon.providers.http.httpclient.impl.execchain.RedirectExec.execute (RedirectExec.java:110)
    at org.apache.maven.wagon.providers.http.httpclient.impl.client.InternalHttpClient.doExecute (InternalHttpClient.java:185)
    at org.apache.maven.wagon.providers.http.httpclient.impl.client.CloseableHttpClient.execute (CloseableHttpClient.java:83)
    at org.apache.maven.wagon.providers.http.wagon.shared.AbstractHttpClientWagon.execute (AbstractHttpClientWagon.java:1005)

Could not transfer artifact

There is another error similar to above error, so here I’ll demonstrate , you may encounter this very likely down the roads.

Check out the error text ArtifactTransferException: Could not transfer artifact, then move on you’ll find SocketException: Connection reset

Caused by: org.eclipse.aether.transfer.ArtifactTransferException: Could not transfer artifact io.micrometer:micrometer-bom:pom:1.3.1 from/to central (https://repo.maven.apache.org/maven2): transfer failed for https://repo.maven.apache.org/maven2/io/micrometer/micrometer-bom/1.3.1/micrometer-bom-1.3.1.pom, proxy: ProxyInfo{host='proxy.stgeorge.com', userName='null', port=8080, type='https', nonProxyHosts='null'}
    at org.eclipse.aether.connector.basic.ArtifactTransportListener.transferFailed (ArtifactTransportListener.java:52)
    at org.eclipse.aether.connector.basic.BasicRepositoryConnector$TaskRunner.run (BasicRepositoryConnector.java:369)
    at org.eclipse.aether.util.concurrency.RunnableErrorForwarder$1.run (RunnableErrorForwarder.java:75)
    at org.eclipse.aether.connector.basic.BasicRepositoryConnector$DirectExecutor.execute (BasicRepositoryConnector.java:628)


...
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read (SocketInputStream.java:186)
    at java.net.SocketInputStream.read (SocketInputStream.java:140)
    at org.apache.maven.wagon.providers.http.httpclient.impl.io.SessionInputBufferImpl.streamRead (SessionInputBufferImpl.java:137)

Troubleshooting & Solutions

Essentially all above errors are related to network connection, more precisely, it caused by incorrect proxy host setup. So the fix is straitforward, check and rectify your proxy configuration.

Guide to fix maven proxy errors

Firstly know where or which settings.xml in used for Maven

Run following command first

mvn -X install -l mvnOutput.log

Open maven output file and search following keyword

So you’ll find the path to the real setting.xml in use

[DEBUG] Reading global settings from c:\dev\apache-maven-3.8.1\bin\..\conf\settings.xml
[DEBUG] Reading user settings from C:\Users\userSpiderMan\.m2\settings.xml

Edit settings.xml to get the proxy host declared

Open the settings.xml found in previous step, normally it’d the file settings.xml under maven conf folder

Check proxy host settings under element <proxy>, for example, make sure the url in host is reachable

<proxies>
	<proxy>
			<id>abcCorpProxySSL</id>
			<active>true</active>
			<protocol>https</protocol>
			<username>username-aaa</username>
			<password>xxxx</password>
			<host>df.proxy.prod.abc.com</host>
            <!-- <host>proxy.abc.com</host> -->
			<!-- <host>dmy-proxy.prod.abc.com/</host> -->
			<port>8080</port>
			<nonProxyHosts>localhost|10.|.btfin.com|.theabcgroup.com|snow.theabcgroup.com|127.0.0.1|nexus.fx.srv.abc.com</nonProxyHosts>
		</proxy>
		
    </proxies>

Update to your workable proxy setup and retry

Once you changed host, username and password, save it and make a retry. Finger crossed and if everything going smoothly, you’ll see the lovely wonderful output as below.

Maven build success

Further reading

There are other Maven errors similiar to this and caused by same rootcause.

503 Service Unavailable, proxy: ProxyInfo

503 Service Unavailable, proxy: ProxyInfo{host='dmy-proxy.prod.abc.com', userName='null', port=8080, type='http', nonProxyHosts='null'} -> [Help 1]
[ERROR] Plugin org.apache.maven.plugins:maven-failsafe-plugin:2.18.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-failsafe-plugin:jar:2.18.1: Could not transfer artifact org.apache.maven.plugins:maven-failsafe-plugin:pom:2.18.1 from/to central (http://nexus.fx.srv.abc.com/content/groups/public): transfer failed for http://nexus.fx.srv.abc.com/content/groups/public/org/apache/maven/plugins/maven-failsafe-plugin/2.18.1/maven-failsafe-plugin-2.18.1.pom, status: 503 Service Unavailable, proxy: ProxyInfo{host='dmy-proxy.prod.abc.com', userName='null', port=8080, type='http', nonProxyHosts='null'} -> [Help 1]

failed: Connection timed out: connect

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:47 min
[INFO] Finished at: 2021-10-06T14:54:47+11:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project notification-service: Could not resolve dependencies for project com.abc.ptt:notification-service:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at com.abc.ptt.messaging:ptt-messaging-common:jar:4.0.0-SNAPSHOT -> com.abc.ptt.messaging:ptt-messagin
g-api:jar:4.0.0-SNAPSHOT: Failed to read artifact descriptor for com.abc.ptt.messaging:ptt-messaging-api:jar:4.0.0-SNAPSHOT: Could not transfer artifact com.abc.ptt.messaging:ptt-messaging-api:pom:4.0.0-SNAPSHOT from/to central (http://nexus.fx.srv.abc.com/content/groups/public): transfer
failed for http://nexus.fx.srv.abc.com/content/groups/public/com/abc/ptt/messaging/ptt-messaging-api/4.0.0-SNAPSHOT/ptt-messaging-api-4.0.0-SNAPSHOT.pom, proxy: ProxyInfo{host='df.proxy.prod.mte.abc.com', userName='null', port=80, type='http', nonProxyHosts='null'}: Connect to df.proxy.
prod.mte.abc.com:80 [df.proxy.prod.mte.abc.com/10.39.66.100] failed: Connection timed out: connect -> [Help 1]

–End–

Updated: