简体   繁体   中英

get maven clean install to work like maven clean + maven install

I have the following project hierarchy:

app
|-module1
| |-pom.xml
|-module2
| |-pom.xml
|-pom.xml

Module1 and module2 both copies files to the same target directory, so im using the app's pom.xml to clear that directory. My problem is, the execution order right now is module1[clean], module1[install], module2[clean], module2[install], app[clean], app[install], so everything module1 and module2 puts into that directory will be deleted.

I would like to get it to execute all clean first, then all install, even when i run mvn clean install. Or if there is another way to execute app[clean] before module1[install] and module2[install], that would work too.

EDIT

I ended up making a separate module (Netbeans POM projekt) for cleaning alone. Not the sollution i was hoping for, but it works for now.

The root of the problem here is that you're trying to make Maven do something that sort-of contradicts Maven's multi-module "conventions", as well as conflicting with Maven's "understanding" of a "target directory". There is a reason why Maven's reactor is operating the way that it does, and it is to preserve the Maven "spirit" (or "convention") of how modules are structured in a multi-module build.

In Maven, the target directory is supposed to belong only to one project: each project has its own target directory. In your scenario, there should really be a different target directory for app , module1 and module2 .

I suppose your best bet, in order to both achieve your objective and keep your build process flexible, is to:

  1. Have module1 output its own JAR into its own target directory ( module1/target ).
  2. Have module2 output its own JAR into its own target directory ( module2/target ).
  3. Add a plugin to app (the parent module) that will collect whatever it needs from module1/target and module2/target into app/target , and do whatever processing on those artifacts.

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