简体   繁体   中英

Can additional Maven dependencies be specified on the command line?

I have a Maven project that is runnable from the command line, and I was planning to use mvn exec:java to run it from some scripts. That project can interface with other different projects in a plugin-type architecture, so I'd like to specify which plugin to load on the command line. The plugins are developed independently from core code, so I'd like to avoid referencing them in the core project's pom if at all possible.

It seems like executableDependency from the exec Maven plugin's configuration may be what I'm looking for, but it doesn't look like I can specify that on the command line.

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

I came across a somewhat similar problem (not in the context of plugins, though) once and I don't believe that's possible.

I did have to find a quick solution back then, and used properties in the pom.xml :

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

And would run it like:

mvn -Dmygid=junit -Dmyaid=junit -Dmyver=4.11 clean package

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM