Maven install error: Dependency could not be resolved - maven

I am using Maven 3.1.1. When I run mvn install I get the following error:
D:\spring source>mvn install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building SpringDependencies 1.0
[INFO] ------------------------------------------------------------------------
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
dependency-plugin/2.8/maven-dependency-plugin-2.8.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.648s
[INFO] Finished at: Mon Dec 16 15:01:47 IST 2013
[INFO] Final Memory: 4M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] Plugin org.apache.maven.plugins:maven-dependency-plugin:2.8 or one of it
s dependencies could not be resolved: Failed to read artifact descriptor for org
.apache.maven.plugins:maven-dependency-plugin:jar:2.8: Could not transfer artifa
ct org.apache.maven.plugins:maven-dependency-plugin:pom:2.8 from/to central (htt
p://repo.maven.apache.org/maven2): repo.maven.apache.org: Unknown host repo.mave
n.apache.org -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[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 rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResoluti
onException
My pom.xml is:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>spring-source-download</groupId>
<artifactId>SpringDependencies</artifactId>
<version>1.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>download-dependencies</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory> ${project.build.directory}/dependencies </outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Could not transfer artifact
org.apache.maven.plugins:maven-dependency-plugin:pom:2.8 from/to
central (http://repo.maven.apache.org/maven2): repo.maven.apache.org:
Unknown host repo.maven.apache.org
It seems like your maven cannot access remote central repository.
Check if you have an established internet connection.
Check if you can access default maven repo http://repo.maven.apache.org/maven2 in your browser.
Check if you have correct configuration in <repositories> and <proxies> in your your settings.xml

This error comes due to the proxy settings.
First of all, check whether you are able to connect to maven repository(http://repo1.maven.org/maven2) from browser.
Then update Maven proxy setting create/update a settings.xml in .m2 directory with following details:
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>{your proxy server host name}</host>
<port>{your proxy server port}</port>
<nonProxyHosts>maven</nonProxyHosts>
</proxy>
</proxies>
Solution given by Maven community: http://maven.apache.org/guides/mini/guide-proxies.html

This is caused by corrupted maven or plugins folder. To resolve this:
Delete \.m2\repository\org\apache\maven
mvn dependency:resolve -X

Where is my Settings.xml?
Windows users
It's in your C:/Users/<Username>/.m2/settings.xml
Also, this is for specific user.
Global one can be present at :
<Maven-Installation-Directory>/conf/settings.xml
But changing the User one might solve the issue if you can't find the global one.
Also, equally important, go to Preferences in Eclipse/STS:
Goto Maven -> User Settings
and verify if both global and user settings.xml files are mentioned in the properties, if not mention them by browsing.
1. Proxy Issue
Check Windows Proxy Setting.
If there is any proxy which your computer is using then you need to add proxy settings in your settings.xml file too.
Just add this chunk of code in your settings.xml
<proxies>
<proxy>
<id>proxy-id</id>
<active>true</active>
<protocol>http</protocol>
<host>ca-something.net</host>
<port>80</port>
<nonProxyHosts>localhost|10.140.240.90.*</nonProxyHosts>
</proxy>
</proxies>
2. Protocol Issue
Visit http://repo.maven.apache.org/: If it says Https required.
Then, you need to add this chunk of code to your settings.xml inside <mirrors>
<mirror>
<id>central-secure</id>
<url>https://repo.maven.apache.org/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
Now it should be good to go.
3. None of the above works
Try disconnecting any company private VPN and try mvn clean build.

Disconnect from VPN and then run the command.

Probably a bit late to the party, but there appears to be an unknown host exception thrown out of maven even if the resource/dependency is unavailable at that address.
Which could mean that the problem may actually be that you have a transitive dependency that is pointing you to the wrong version of a jar (or one that is transitively included multiple times - one of which may be an unresolvable version). (I see it's looking for version 2.8 of the plugin but you specified version 3.1.1, so it's likely you have another dependency transitively including the wrong version).
You can exclude transitive inclusion of a dependency using the exclusions tag.

This issue was resolved for us by providing the correct proxy host in .m2/settings.xml.
Example:
<proxies>
<proxy>
<id>XXXXXXXXXX</id>
<active>true</active>
<protocol>http</protocol>
<host>na-xxxx-proxy.na.xxxxxxxxxx.net</host>
<port>80</port>
<nonProxyHosts>localhost|10.140.240.90.*</nonProxyHosts>
</proxy>
</proxies>

Related

Push docker image to Nexus

Hello I have Jenkins and Nexus on the same server. When Jenkins build project correctly, i want push image to Nexus 3, but every time i have the same problem (log below).
Configuration:
pom.xml
<nexus.url>http://adress/#browse/browse/components:docker-image</nexus.url>
<distributionManagement>
<snapshotRepository>
<id>nexus</id>
<url>${nexus.url}</url>
</snapshotRepository>
</distributionManagement>
...
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.4</version>
<extensions>true</extensions>
<configuration>
<serverId>nexus</serverId>
<nexusUrl>${nexus.url}</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
And i have file settings.xml:
<servers>
<server>
<id>nexus</id>
<username>login</username>
<password>password</password>
</server>
</servers>
Then i try "mvn clean deploy" and result is:
[INFO] Deploying remotely...
[INFO] Bulk deploying locally gathered artifacts from directory:
[INFO] * Bulk deploying locally gathered snapshot artifacts to URL http://adress/repository/image-docker/
Downloading: http://adress/repository/image-docker/someProject/0.1-SNAPSHOT/maven-metadata.xml
Uploading: http://adress/repository/image-docker/someProject/0.1-SNAPSHOT/someProject-0.1-20161213.093022-1.jar
Uploading: http://adress/repository/image-docker/someProject//0.1-SNAPSHOT/someProject-0.1-20161213.093022-1.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:58 min
[INFO] Finished at: 2016-12-13T10:30:35+01:00
[INFO] Final Memory: 75M/748M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonatype.plugins:nexus-staging-maven-plugin:1.6.4:deploy (injected-nexus-deploy) on project someProject:
Failed to deploy artifacts: Could not transfer artifact someProject:jar:0.1-20161213.093022-1 from/to nexus (http://adress/repository/image-docker/):
Failed to transfer file: http://adress/repository/image-docker/someProject/someProject/0.1-SNAPSHOT/someProject-0.1-20161213.093022-1.jar.
Return code is: 502, ReasonPhrase: Bad Gateway. -> [Help 1]
Every time is the same problem with 502 - Bad Gateway.
Do you have some proposal?
Unfortunately this will not work for a few reasons.
The URL you are using as a Nexus url is wrong, that URL is the browser URL. You need to use something more akin to https://nexusurl:portofdockerhostedrepo/repository/nameofdockerhostedrepo. You can get more information on setting up and pushing Docker images here: https://books.sonatype.com/nexus-book/reference3/docker.html#docker-push
Unless I'm completely wrong, mvn deploy is primarily for deploying maven artifacts into Maven repositories. I don't think this will work if you are attempting to deploy a Docker image. You might take a look at using something like this: https://github.com/spotify/docker-maven-plugin
Hope this helps.

How to deploy an artifact into Amazon S3 with Maven?

I'm trying to follow these tutorials (1,2) to achieve the mentioned goal. But I'm still getting this error from Maven:
INFO] Installing /home/valter/temp-workspace/document-engine/target/application-1.0.0.CI-SNAPSHOT.jar to /home/valter/.m2/repository/com/company-solutions/application/1.0.0.CI-SNAPSHOT/application-1.0.0.CI-SNAPSHOT.jar
[INFO] Installing /home/valter/temp-workspace/document-engine/pom.xml to /home/valter/.m2/repository/com/company-solutions/application/1.0.0.CI-SNAPSHOT/application-1.0.0.CI-SNAPSHOT.pom
[INFO]
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) # application ---
Downloading: s3://myrepo.company.solutions/snapshot/com/company-solutions/application/1.0.0.CI-SNAPSHOT/maven-metadata.xml
[WARNING] s3://myrepo.company.solutions/snapshot - Connection refused
[WARNING] Could not transfer metadata com.company-solutions:application:1.0.0.CI-SNAPSHOT/maven-metadata.xml from/to s3.snapshot (s3://myrepo.company.solutions/snapshot): Could not connect to repository
[INFO] Logged off - myrepo.company.solutions
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:31 min
[INFO] Finished at: 2015-11-16T18:36:26+01:00
[INFO] Final Memory: 181M/1289M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project application: Failed to retrieve remote metadata com.company-solutions:application:1.0.0.CI-SNAPSHOT/maven-metadata.xml: Could not transfer metadata com.company-solutions:application:1.0.0.CI-SNAPSHOT/maven-metadata.xml from/to s3.snapshot (s3://myrepo.company.solutions/snapshot): Could not connect to repository: Status Code: 400, AWS Service: Amazon S3, AWS Request ID: 709B60A05E8E7062, AWS Error Code: InvalidRequest, AWS Error Message: The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256. -> [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/MojoExecutionException
These are my local files, ~.m2/settings.xml (with fictious values, of course):
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>s3.site</id>
<username>access_key</username>
<password>private_key</password>
</server>
<server>
<id>s3.release</id>
<username>access_key</username>
<password>private_key</password>
</server>
<server>
<id>s3.snapshot</id>
<username>access_key</username>
<password>private_key</password>
</server>
</servers>
</settings>
And my pom.xml:
<project>
<build>
<extensions>
<extension>
<groupId>org.kuali.maven.wagons</groupId>
<artifactId>maven-s3-wagon</artifactId>
<version>1.2.1</version>
</extension>
</extensions>
...
</build>
<distributionManagement>
<site>
<id>s3.site</id>
<url>s3://myrepo.company.solutions/site</url>
</site>
<repository>
<id>s3.release</id>
<url>s3://myrepo.company.solutions/release</url>
</repository>
<snapshotRepository>
<id>s3.snapshot</id>
<url>s3://myrepo.company.solutions/snapshot</url>
</snapshotRepository>
</distributionManagement>
...
</project>
I'm using Maven 3.3.3.
EDIT
This is my policy simulator result:
Just to let you guys know what happened.
The problem was the region of my bucket was Frankfurt, which requires the newest version of authentication from Amazon AWS, version 4. As far as I can tell, the plugin aws-maven doesn't support this new version right now. So the solutions was to move my bucket to another region which support the older version of schemes, like US Standard. And everything seems to work fine now!

Releasing to Maven Central

I was added as a developer to the Maven project and now I need to make a release.
I've added nexus-staging-maven-plugin to pom.xml file.
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.3</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
Also I've added distributionManagement to pom.xml
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
I've placed my credentials to ~/.m2/settings.xml
<settings>
<servers>
<server>
<id>ossrh</id>
<username>divanov-oss.sonatype.org-account</username>
<password>divanov-oss.sonatype.org-password</password>
</server>
</servers>
</settings>
I also tried to create and use "Access User Token" on oss.sonatype.org
as my credentials.
Now I'm executing to deploy release into maven central.
mvn clean deploy
which ends up in the error:
[ERROR] Failed to execute goal org.sonatype.plugins:nexus-staging-maven-plugin:1.6.3:deploy
(injected-nexus-deploy) on project project: Failed to deploy artifacts:
Could not transfer artifact
project:jar:4.4.0-20141228.104011-1 from/to ossrh
(https://oss.sonatype.org/content/repositories/snapshots): Access denied to:
https://oss.sonatype.org/content/repositories/snapshots/project/project/4.4.0-SNAPSHOT/project-4.4.0-20141228.104011-1.jar,
ReasonPhrase: Forbidden. -> [Help 1]
or
[INFO] Performing remote staging...
[INFO]
[INFO] * Remote staging into staging profile ID "329a0bc2b7ce06"
[ERROR] Remote staging finished with a failure: 403 - Forbidden
[ERROR]
[ERROR] Possible causes of 403 Forbidden:
[ERROR] * you have no permissions to stage against profile with ID "329a0bc2b7ce06"? Get to Nexus admin...
How can I check my access rights within Maven project I'm trying to release?
Your credentials are likely fine, you'd be getting a 401 error if they weren't. You're getting 403 (forbidden). This means the credentials were accepted, but you don't have permission to publish the artifacts. The most common cause of this is that you are using a different Maven group ID than the one assigned to you. File an issue at https://issues.sonatype.org in the "Community Support - Open Source Project Repository Hosting" and we'll get this worked out.
The credentials that you need to use shouldn't be of Sonatype JIRA, but of oss.sonatype.org. You need to register there separately.
[Update] The question was changed, so this answer is not relevant anymore. I'll keep it, since it's a common mistake.

Selenium2 Build Error in Maven apache-maven-3.0.5

I came across following error in Maven when run the command
C:\Users\Man\SelProj>mvn clean install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building SelProj 1.0
[INFO] ------------------------------------------------------------------------
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.4.1/maven-clean-plugin-2.4.1.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.735s
[INFO] Finished at: Sun Apr 21 15:25:23 EST 2013
[INFO] Final Memory: 6M/106M
[INFO] ------------------------------------------------------------------------
[ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.4.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:m
aven-clean-plugin:jar:2.4.1: Could not transfer artifact org.apache.maven.plugins:maven-clean-plugin:pom:2.4.1 from/to central (http://repo.maven.apache.org/maven2): Connection to
http://repo.maven.apache.org refused: connect: Address is invalid on local machine, or port is not valid on remote machine -> [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/PluginResolutionException
C:\Users\Man\SelProj>
My POM.xml file as follows, I placed the POM file in the folder where I am running the >mvn clean install cmmand
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>SelProj</groupId>
<artifactId>SelProj</artifactId>
<version>1.0</version>
<dependencies>
<!-- Selenium2 dependency -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.32.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>2.5.0</version>
</dependency>
</dependencies>
</project>
What could be the reason. I am running this on windows 8 (64 bit)
I also had same issue. Try to use just >mvn install command without clean.
Since you can access it via the web browser, I understand that there is no any issue about the internet connection.
There are 2 significant possible root causes as the following: -
1. The proxy
If you are behind the proxy, please add the proxy configuration to the settings.xml e.g.
<settings>
.
.
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>proxy.somewhere.com</host>
<port>8080</port>
<username>proxyuser</username>
<password>somepassword</password>
<nonProxyHosts>www.google.com|*.somewhere.com</nonProxyHosts>
</proxy>
</proxies>
.
.
</settings>
Please see Maven - Guide to using proxies for further information.
2. The Anti-Virus / Firewall Issue
Firewall and Anti-virus sometimes prevent Java from running properly, or Windows Firewall (and various other Firewalls) actively prevent Java.exe from reaching out to the Internet to "download stuff" which is a key part of Maven. You may need to configure the Firewall or Anti-virus to add exceptions to allow such actions.
Please see Maven - Maven on Windows for further information.
I hope this may help.

Could not connect to remote://localhost:9999. The connection timed out Jboss 7.1.1 Final

I am deploying builds to local and remote Jboss AS 7.1.1 Final at port 9999. Maven uses jboss plugin 'jboss-as-maven-plugin:7.1.1.Final' to manage builds to servers. I have confirmed that server is up and running and port is accessible at 9999. But "many times" build fails with following error for both local and remote Jboss. Jboss ic configured in Standalone mode single node cluster.
Stranglely build doesn't fail every time but most of the time. Not sure if we need to upgrade Maven plugin to higher version.
[INFO] o.h.m.e.h.MavenExecutionResultHandler - Build failed with
exception(s) [INFO] o.h.m.e.h.MavenExecutionResultHandler - [1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to
execute goal
org.jboss.as.plugins:jboss-as-maven-plugin:7.1.1.Final:undeploy
(default-cli) on project Test: Error executing UNDEPLOY [DEBUG]
Closing connection to remote [ERROR] Failed to execute goal
org.jboss.as.plugins:jboss-as-maven-plugin:7.1.1.Final:undeploy
(default-cli) on project Test: Error executing UNDEPLOY:
java.net.ConnectException: JBAS012144: Could not connect to
remote://localhost:9999. The connection timed out -> [Help 1]
UPDATE
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.1.1.Final</version>
<configuration>
<filename>${project.build.finalName}.jar</filename>
<username>${userName}</username>
<password>${password}</password>
</configuration>
</plugin>
I am now using latest version of Maven plug-in but it seems that connection timeout error is more frequent now. I am starting to think if Jboss behaves differently when trying to make too many remote deployment with different sub projects of the application. I am having 21 sub projects being deployed from a master POM. Sample configuration is as follows
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.master</groupId>
<artifactId>master</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<name>Master</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<modules>
<module>module1</module>
<module>module2</module>
<module>module3</module>
<module>module4</module>
<module>module5</module>
<module>module6</module>
<module>module7</module>
<module>module8</module>
<module>module9</module>
<module>module10</module>
<module>module11</module>
<module>module12</module>
<module>module13</module>
</modules>
First, check plugin configuration.
For example:
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.9.Final</version>
<inherited>true</inherited>
<configuration>
<hostname>${jboss.hostname}</hostname>
<port>${jboss.port}</port>
<username>${jboss.user}</username>
<password>${jboss.pass}</password>
<timeout>30000</timeout>
</configuration>
</plugin>
If hostname, port number(default 9999), username and password are ok, you can try increasing "timeout" (default is 5000ms, you can try with 30000ms).
It worked for me.
4 Possible Solutions to Question
Remove your Local Cache settings which will be your local m2 repo Or Point to new m2 repo from your maven settings.xml file.
Try to connect to your local nexus/archiva (if any other) using relevant/appropriate credentials.It is only your Maven Plugin causing this problem.
Try to use the latest JBoss Deploy Plugin available in this link.
Alternatively check your windows/Linux firewall settings have been enabled or it.

Resources