Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if a Maven artifact is in my repo from command line?

Tags:

I would like to check from command line if a certain coordinate (groupId.artifactId.version) can be found in a repository.

If it is possible, can it be done with partial coordinates (e.g artifactId.version)? Can I specify the repo?

I do not ask for workarounds - I could simply start a file search in my local repo, or enter the artifact in a POM and wait for errors, or install Nexus and search over the UI...

It is a convenience thing - once on the CLI, it would be nice to be able to check quickly.

like image 492
kostja Avatar asked Apr 16 '12 15:04

kostja


People also ask

What is used to identify a Maven artifact?

Artifacts in maven are identified by a coordinate system of groupId, artifactId, and version. Maven uses the groupId , artifactId , and version to identify dependencies (usually other jar files) needed to build and run your code.

What is Maven artifact repository?

As a Maven repository, Artifactory is both a source for artifacts needed for a build, and a target to deploy artifacts generated in the build process. Maven is configured using a settings. xml file located under your Maven home directory (typically, this will be /user.

Where is Maven repository located in CMD?

For windows users Usually it's in: C:\Users\USER_NAME\. m2\repository . However the mvn help:effective-settings command will surely show the local path in response xml.

How do you analyze a dependency tree in Maven?

A project's dependency tree can be filtered to locate specific dependencies. For example, to find out why Velocity is being used by the Maven Dependency Plugin, we can execute the following in the project's directory: mvn dependency:tree -Dincludes=velocity:velocity.


1 Answers

Here's the closest I think you'll get:

mvn dependency:get -Dartifact=g:a:v -o -DrepoUrl=file://path/to/your/repo 

I'v tried it, it succeeds if the artifact (e.g. "junit:junit:4.8.2") is in your repo and fails if it isn't, but you have to write the full path to your local repo as an URL.

The key is to use the -o (offline) flag, because otherwise maven will always check the central repo.

like image 175
Sean Patrick Floyd Avatar answered Oct 05 '22 01:10

Sean Patrick Floyd