Can I specify additional Maven dependencies on the command line?

I have a Maven project that starts from the command line, and I planned to use mvn exec:java to run it from some scripts. This project can interact with various other projects in the plugin architecture, so I would like to indicate which plugin to load on the command line. Plugins are developed independently of the underlying code, so I would like to avoid referencing them in the main pom project, if at all possible.

It looks like the executableDependency from the exec configuration of the Maven plugin may be what I'm looking for, but it doesn't seem like I can specify this on the command line.

+4
source share
2 answers

You can use Maven profiles . Use different profiles for different use cases and activate the profile command line. A profile can contain dependencies and plugins that will be used only if this profile is activated.

+2
source

I ran into some similar problem (not in the context of plugins, though), and I don't think this is possible.

Then I needed to find a quick solution and use the properties in pom.xml :

 <dependency> <groupId>${mygid}</groupId> <artifactId>${myaid}</artifactId> <version>${myver}</version> </dependency> 

And it will run as:

 mvn -Dmygid=junit -Dmyaid=junit -Dmyver=4.11 clean package 
+2
source

Source: https://habr.com/ru/post/1480520/


All Articles