How can I download a specific Maven artifact from repository to local drive? - maven

There might be some times that we want to download a specific Maven artifact from repository to local drive.
In my case, I would like to use a third party library published in Maven repository in a particular IDE. However, the IDE I use has no integration support for maven repository yet, therefore the only way to use this library is to download the artifact to my local drive.
I'm a newbie for maven, any suggestions will be very appreciated. Thanks.
-----UPDATE------
I learned from other threads and realised I should use maven dependency plugin to download an artifact to local folder. In my case, I need to download google ARCore from maven repository. I search the ARCore at maven repository, and know that:
Category: com.google.ar, Group:core, version:1.1.0
So I used the following command line to download it:
mvn dependency:get -Dartifact=com.google.ar:core:1.1.0
However, it failed to download the artifact, the error message is like:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.8:get (default-cli) on project standalone-pom: Couldn't download artifact: Missing:
[ERROR] ----------
[ERROR] 1) com.google.ar:core:jar:1.1.0
[ERROR]
[ERROR] Try downloading the file manually from the project website.
[ERROR]
[ERROR] Then, install it using the command:
[ERROR] mvn install:install-file -DgroupId=com.google.ar -DartifactId=core -Dversion=1.1.0 -Dpackaging=jar -Dfile=/path/to/file
[ERROR]
[ERROR] Alternatively, if you host your own repository you can deploy the file there:
[ERROR] mvn deploy:deploy-file -DgroupId=com.google.ar -DartifactId=core -Dversion=1.1.0 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
[ERROR]
[ERROR] Path to dependency:
[ERROR] 1) org.apache.maven.plugins:maven-downloader-plugin:jar:1.0
[ERROR] 2) com.google.ar:core:jar:1.1.0
[ERROR]
[ERROR] ----------
[ERROR] 1 required artifact is missing.
Anyone can give a help? Thanks.

If you look at the documentation of the artifact option though:
A string of the form groupId:artifactId:version[:packaging][:classifier].
Look at its last (optional) token, [:classifier]. I think That is what you are missing.
try this one,
mvn dependency:get -Dartifact=com.google.ar:core:1.1.0:jar:jar-with-dependencies

Related

Using the parameter "LATEST' while building the project does not work with "mvn clean install"

If we use the 'LATEST' parameter when generating the project, the command 'mvn clean install' errors out. Should this parameter be used or should the latest version be provided in the command?
mvn archetype:generate "-DarchetypeGroupId=com.sap.cloud.s4hana.archetypes" "-DarchetypeArtifactId=scp-cf-tomee" **"-DarchetypeVersion=LATEST**" "-DgroupId=com.sap.cloud.s4hana.examples" "-DartifactId=my-app" "-Dversion=1.0-SNAPSHOT"
Error is
Error:
[INFO] Scanning for projects...
Downloading: https://repo.maven.apache.org/maven2/org/springframework/spring-framework-bom/5.1.1.RELEASE/spring-framework-bom-5.1.1.RELEASE.pom
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] Non-resolvable import POM: Could not transfer artifact org.springframework:spring-framework-bom:pom:5.1.1.RELEASE from/to central (https://repo.maven.apache.org/maven2): proxy.myproxy.corp # com.sap.cloud.s4hana:sdk-bom:2.7.1-SNAPSHOT, C:\Users\xxxxxxx\.m2\repository\com\sap\cloud\s4hana\sdk-bom\2.7.1-SNAPSHOT\sdk-bom-2.7.1-SNAPSHOT.pom, line 994, column 25
#[ERROR] The build could not read 1 project -> [Help 1]
[ERROR][ERROR] The project com.sap.cloud.s4hana.examples:address-manager1:1.0-SNAPSHOT (C:\my-app\pom.xml) has 1 error
[ERROR] Non-resolvable import POM: Could not transfer artifact org.springframework:spring-framework-bom:pom:5.1.1.RELEASE from/to central (https://repo.maven.apache.org/maven2): proxy.wdf.sap.corp # com.sap.cloud.s4hana:sdk-bom:2.7.1-SNAPSHOT, C:\Users\xxxxxx\.m2\repository\com\sap\cloud\s4hana\sdk-bom\2.7.1-SNAPSHOT\sdk-bom-2.7.1-SNAPSHOT.pom, line 994, column 25: Unknown host proxy.myproxy.corp -> [Help 2]
[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/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
The version 2.7.1-SNAPSHOT in not a released version. It is not available externally (maven-central). So, you cannot download it from maven central. However, 2.6.1 is available. That is why it works.
Please try with RELEASE instead of LATEST or better use released versions directly.
Please also check that settings.xml does not point to an internal snapshot nexus server and delete the local repository in your .m2 directory.
Have you checked your network configuration?
I can see a proxy and unknown host error in the log.

Manual dependency Maven and Jenkins

I have created a Job in Jenkins with some goals in Maven (clean verify compile).
But, when I run the Job has the error:
[ERROR] Failed to execute goal on project NameProject: Could not resolve dependencies for project NameProject:x:war:0.0.1-SNAPSHOT: The following artifacts could not be resolved: com.oracle:ojdbc14:jar:10.2.0.5, org.primefaces.themes:sentinel-theme:jar:2.1.2: Could not find artifact com.oracle:ojdbc14:jar:10.2.0.5 in central (https://repo.maven.apache.org/maven2) -> [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
I have created manual dependency in Maven
mvn install:install-file
-Dfile=<path-to-file>
-DgroupId=<group-id>
-DartifactId=<artifact-id>
-Dversion=<version>
-Dpackaging=<packaging>
-DgeneratePom=true
,but Jenkins doesn't know this dependency in the pom.
When I execute verify compile in Maven it's works!, But when I execute in Jenkins doesn't work.
If you want to install it into a local repository, you need to install it into the local repository that is used by the Jenkins Server,i.e. you need to start mvn install on the Jenkins server.
If you have a company Nexus server, it is probably better to install it there.
I have changed the default local repository Maven
<localRepository>C:/Users/nameUser/.m2/repository</localRepository>
My Maven diretory was in a another drive (E:/), when repository in (C:).

Maven dependency issue in Mule project

I'm not able to find this particular maven dependency while creating new Maven support enabled project in AnypointStudio. Same issue comes when I try to mavenize an existing Mule project. Has anyone solved this?
Anypoint Studio version - 5.4.3
Mule runtime version - 3.6.1
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.4:copy (copy-clover-plugins) on project tradeshift-connector: Unable to find artifact. Failure to find com.cloveretl:cloveretl-engine:zip:3.6.1 in http://repo1.maven.org/maven2/ was cached in the local repository, resolution will not be reattempted until the update interval of Central has elapsed or updates are forced
[ERROR]
[ERROR] Try downloading the file manually from the project website.
[ERROR]
[ERROR] Then, install it using the command:
[ERROR] mvn install:install-file -DgroupId=com.cloveretl -DartifactId=cloveretl-engine -Dversion=3.6.1 -Dpackaging=zip -Dfile=/path/to/file
[ERROR]
[ERROR] Alternatively, if you host your own repository you can deploy the file there:
[ERROR] mvn deploy:deploy-file -DgroupId=com.cloveretl -DartifactId=cloveretl-engine -Dversion=3.6.1 -Dpackaging=zip -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
[ERROR]
[ERROR]
[ERROR] com.cloveretl:cloveretl-engine:zip:3.6.1
[ERROR]
[ERROR] from the specified remote repositories:
[ERROR] Central (http://repo1.maven.org/maven2/, releases=true, snapshots=true),
[ERROR] mulesoft-releases (http://repository.mulesoft.org/releases/, releases=true, snapshots=true),
[ERROR] central (https://repo.maven.apache.org/maven2, releases=true, snapshots=false)
Go to your local M2_REPO folder and delete contents of /com/cloveretl. That will force Maven to pull it again.
Go to your local .m2 repo and delete the contents of /com/cloveretl, as others have suggested.
Mule recreates the folder correctly but the ZIP file is called cloveretl-engine-3.6.1.zip.lastupdated.
Rename to cloveretl-engine-3.6.1.zip and it works fine.

Spring MVC issues in STS 3.7.3

I am getting this error on importing https://github.com/spring-projects/spring-mvc-showcase in STS 3.7.3:---
Description Resource Path Location Type
Failure to transfer org.codehaus.mojo:aspectj-maven-plugin:pom:1.2 from https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.codehaus.mojo:aspectj-maven-plugin:pom:1.2 from/to central: connect timed out pom.xml /spring-mvc-showcase line 1 Maven pom Loading Problem
Edit
Mvn is ok now but pom.xml error still persists if I remove the errors and do maven clean I get errors as:
[INFO] https://repo.maven.apache.org/maven2/org/codehaus/mojo/aspectj-maven-plugin/1.2/aspectj-maven-plugin-1.2.pom [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [ERROR] Plugin org.codehaus.mojo:aspectj-maven-plugin:1.2 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.codehaus.mojo:aspectj-maven-plugin:jar:1.2: Could not transfer artifact org.codehaus.mojo:aspectj-maven-plugin:pom:1.2 from/to central: connect timed out -> [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
First of all STS is build on Eclipse. So you can easily install the IDE Integration Eclipse IDE - M2Eclipse for STS. You can see how here. If you want to use it with this integration plugin you dont need to have a local maven repository.
Resolving Maven dependencies from the Eclipse workspace without installing to local Maven repository
But its also possible to use maven as a local system repository. Download is here and follow the steps for the installation and configuration here.
To see if you have a valid maven installation done, you can test it by typing mvn -v in a cmd shell or using STS -> right click on your project -> run as -> maven build or maven install.
Update:
I would say delete the project from your workspace and try it again. Download the project from gitHub as a zip file and import it again to your workspace. Right Click -> import -> existing maven project.
If you need to use a proxy for your connection you have to create a settings.xml in your .m2 folder. Look here for more info

Maven says archetype does not exist

I am trying to create a JPA based project using Maven and eclipse. I tried using the jpa-maven-archetype from create new maven project in the eclipse project creation, but it shot back this error
Could not resolve archetype com.rfc.maven.archetypes:jpa-maven-archetype:RELEASE from any of the configured repositories.
Could not resolve artifact com.rfc.maven.archetypes:jpa-maven-archetype:pom:RELEASE
Failed to resolve version for com.rfc.maven.archetypes:jpa-maven-archetype:pom:RELEASE: Could not find metadata com.rfc.maven.archetypes:jpa-maven-archetype/maven-metadata.xml in local (/home/sebastian/.m2/repository)
Failed to resolve version for com.rfc.maven.archetypes:jpa-maven-archetype:pom:RELEASE: Could not find metadata com.rfc.maven.archetypes:jpa-maven-archetype/maven-metadata.xml in local (/home/sebastian/.m2/repository)
Basically the eclipse plugin is looking into my local repositories instead of remote ones. So I tried going the command line and explicitly specifying the remote repository with the following command
mvn org.apache.maven.plugins:maven-archetype-plugin:1.0-alpha-7:create \
-DgroupId=com.something -DartifactId=jpaexample \
-DarchetypeArtifactId=jpa-maven-archetype \
-DarchetypeVersion=RELEASE \
-DremoteRepositories=http://maven.rodcoffin.com/repo \
-DinteractiveMode=false
And I got this error
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:1.0-alpha-7:create (default-cli) on project standalone-pom: Error creating from archetype: Error attempting to download archetype. Error downloading. Failed to resolve version for org.apache.maven.archetypes:jpa-maven-archetype:jar:RELEASE: Could not find metadata org.apache.maven.archetypes:jpa-maven-archetype/maven-metadata.xml in local (/home/sebastian/.m2/repository)
[ERROR] org.apache.maven.archetypes:jpa-maven-archetype:jar:RELEASE
[ERROR]
[ERROR] from the specified remote repositories:
[ERROR] id0 (http://maven.rodcoffin.com/repo, releases=true, snapshots=true)
[ERROR] -> [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
It seems that repo maven.rodcoffin.com/repo is not working, or there is something wrong with my maven setup. I am not sure which one, if some one could give me pointers on where to search for, that would be helpful.
Also if repo maven.rodcoffin.com/repo is not working. What are my other options to create a JPA archetype project. Do I have to make a simple maven project and then convert it to a JPA as shown here.
EDIT: I just weaseled out of the problem by creating a maven quick type achetype and then using the persistence.xml for my project.
So just ignore this question.

Resources