Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
527 views
in Technique[技术] by (71.8m points)

java - Running a specific Maven plugin goal from the command line in a sub-module of a multi-module reactor project

I'm looking for a general technique here, but let's give a specific example. I have a multi-module project and I'd like to run the exec:java goal from the command-line against one of the sub-modules of my project.

I know one approach is that I can run mvn install on the whole project and then just go into the sub-module directory, run the exec:java command from the command line, and have artifacts resolved to my local repository.?But running mvn install all the time gets pretty tedious.

What I'd really like is the ability to run exec:java against the Maven reactor, where the classpath is constructed from the active modules of the project in the Maven reactor. The problem is that I'm not sure this is possible.?A naive approach is to run the exec:java goal from the root of the project, but this tries to run the plugin against every module in the project, as opposed to the target module I'm interested in.

Any idea? I know my motivating example was exec:java, but really there are a number of single plugin goals that I'd like to run against my project from time to time outside of the scope of the full build lifecycle.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have a multi-module project and I'd like to run the exec:java plugin from the command-line against one of the sub-modules of my project.

I'm not saying that this will fit your exact use case but it is possible to run a goal on a subset of a multi-modules build using the -pl, --projects <arg> option:

mvn exec:java -pl my-module

I know one approach is that I can run "mvn install" on the whole project and then just go into the sub-module directory, run the exec:java command from the command line, and have artifacts resolved to my local repository.

Dependency resolution is indeed done through the local repository.

What I'd really like is the ability to run exec:java against the Maven reactor, where the classpath is constructed from the active modules of the project in the Maven reactor.

That's not really what a reactor build does. A reactor build constructs an oriented graph of the modules, derives an appropriate build order from this graph and runs the goal / phase against the modules in the calculated order. A reactor build doesn't construct some "global" classpath.

A naive approach is to run the exec:java goal from the root of the project, but this tries to run the plugin against every module in the project, as opposed to the target module I'm interested in.

Well, this is the expected behavior. It just doesn't seem to be what you're actually looking for.

Any idea? I know my motivating example was exec:java, but really there are a number of single plugin goals that I'd like to run against my project from time to time outside of the scope of the full build lifecycle

A reactor build does allow this but, as I wrote, you seem to be looking for something different. Maybe If you clarify your exact need, I would be able to provide a better answer.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...