Maven: Command line to download the dependencies described in the pom.xml - maven

I would like to know the maven command line to download the dependencies described in the pom.xml.
It is that : mvn dependency:copy-dependencies ?

Try the dependency:go-offline goal. It's meant to be used to resolve dependencies to the local repo before using the -o switch to go to offline mode. But the goal itself has no bearing on going offline. The name may be misleading.
Goal that resolves all project dependencies, including plugins and reports and their dependencies.
Here's the details about the dependency:copy-dependencies in case you're interested
Anther option is the dependency:resolve goal
Goal that resolves the project dependencies from the repository.

Related

Run mvn exec:exec without a pom.xml

I am trying to find a way just to fetch a library from maven repository and run it. I want to define everything by command line and ignore the pom. I am trying following:
mvn exec:exec -Dexec.mainClass="org.main.Class" -Dspring.profiles.active=test
When I try to run it with pom.xml, it starts to fetch all the dependencies described in the pom. Which I really don't want. When I run it without the pom.xml, it says Goal requires a project to execute but there is no POM in this directory. Please verify you invoked Maven from the correct directory. Is there a way to run it without the pom or at least ignore it?
My goal is just to start my application from anywhere without sources or jars.
One possible workaround would be to:
first get the jar
then execute it
For that, the maven plugin dependency:get is handy, and can be executed without any pom.xml/project (so from any folder you want)
mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get -DrepoUrl=https://dtp.intramundi.com/nexus/repository/maven-central/ -Dartifact=<group>:<artifact>:<version>
Once you have copied the artifact to the folder of your choice, a plugin like dependency:copy-dependencies could, reading the pom.xml of the artifact you just got, copy said dependencies to the same folder of your choice.
Finally, a java -cp . yourArtifact.jar can execute it.
I realize this is not as straightforward as just "exec:exec", and that it fetches dependencies from the pom.xml, but here at least:
the first step does not require any pom.xml,
the second step needs the pom.xml of the very artifact you want to execute, and those dependencies might be needed at runtime: you would need those anyway if you want to 'exec' your artifact.
Nope. It's impossible. Mvn Exec is, in fact, Maven Pluging dedicated to execute something as part of maven-nature project. If you need to execute Jar outcome why not use just java ***.jar ?

How to get all the specified jars mentioned in the pom.xml and transitively dependent jars?

I have only the POM file using which I need to write a script to automatically download all the dependency files and output to custom mentioned path.
I just want to achieve the above using mvn command in command line.
It sounds like you're looking for mvn dependency:copy-dependencies:
dependency:copy-dependencies takes the list of project direct dependencies and optionally transitive dependencies and copies them to a specified location, stripping the version if desired. This goal can also be run from the command line.
From the project root, invoking on the command line
mvn dependency:copy-dependencies -DoutputDirectory=...
will copy all your project direct and transitive dependencies to the specified output directory. If those dependencies are not already in your local Maven repository, they will be downloaded from Maven Central (or from a custom repository).

How to find out which maven artifact/plugin is requesting for the download of a no longer available dependency

I was compiling an "old" open sourced project, while encountered this problem:
[ERROR] Failed to execute goal on project .... Can not transfer artifact x:y:z from ...
the artifact x:y:z is not found from all repositories defined in the project pom.xml.
After looked up the effective pom.xml, I could not find any references to x:y:z.
How can I find out which artifact or plugin is requesting a missing dependency without analyze all transitive dependencies?
If you use eclipe - you can see dep tree like this: open pom.xml and tick "Dependency Hierarchy" tab.
Also you can try to use mvn dependency:tree but I am not totally sure that it will work if some of your deps are missing.
UPDATE: seems like both eclipse and dependency:tree require sucessfull artifact resolution to work whch is not your case.
In this case I guess you're left with 3 opttions:
clean your cache (wipe everything under ~/.m2/repository), run your build and do occurence search (search for something like "problematic-artifact-id") on files in your ~/.m2/repository. One or couple of the artifacts should reference the problematic artifact in their pom. This should give you a hint.
clean your cache and run your build with -X switch. This will put maven in verbosity mode and you should find some hints about what might reference dead dependency (point your attention on download order, what artifacts got resolved, check dependencies of resolved artifacts in their poms)
dumb as hell - comment/uncomment deps in your pom and see what causes the mentioned error.

Maven POM error - POM is missing

I am trying to build a maven project. My other team members are able to build it without issues. I get the following errors:
[WARNING] The POM for org.hectorclient:hector-core:jar:1.0-3 is missing, no dependency information
available
[WARNING] The POM for org.hectorclient:hector-test:jar:1.0-3 is missing, no dependency information
available
Then the build fails with the error: Could not resolve dependencies for the project XYZ. What could be possibly going wrong?
Surely the jar is missing from your .m2 local repository.
Assuming the dependency is written in the pom.
What I suggest:
Case: When you have internet
fire mvn install that will follow your POM.xml and it will download all the necessary jars.
then fire mvn compile to build.
Case: You are having restricted internet connection that is restricting / no Internet
Take the repository + POM from other machine that is compiling successfully
then fire mvn -o compile
I assume it will solve your case.
#Vaibs You are correct. Adding to your answer:
"Check the settings.xml of yours and the others. If you are not able to download the dependencies from internet like the one you mentioned due to some reason then you will need to set up maven somewhere else and and fire "mvn install" there to get the latest dependencies and put those .m2 into yours."

Maven downloading a pom and executing goals

I've been searching around but I could not find the answer.
What I want is to download a pom.xml dependency, and execute some goals (profiles) against it.
I mean:
pom a -> mvn clean install -Psome
donwload the pom b and execute clean package -Panother
This is quite easy with the maven-exec plugin. And I already download the pom with the dependency plugin.
But I wonder if there is a specific plugin.
You could look at bootstrapping a maven project which is supported by maven scm plugin. This assumes you have the pom in an scm.

Resources