简体   繁体   English

使maven全新安装像maven clean + maven install一样工作

[英]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. Module1和module2都将文件复制到相同的目标目录,因此我使用应用程序的pom.xml清除了该目录。 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. 我的问题是,现在的执行顺序是module1 [clean],module1 [install],module2 [clean],module2 [install],app [clean],app [install],因此,module1和module2放入该目录的所有内容都会被删除。

I would like to get it to execute all clean first, then all install, even when i run mvn clean install. 我想让它先执行所有清理,然后执行所有安装,即使我运行mvn clean install。 Or if there is another way to execute app[clean] before module1[install] and module2[install], that would work too. 或者,如果在module1 [install]和module2 [install]之前还有另一种执行app [clean]的方法,那也可以。

EDIT 编辑

I ended up making a separate module (Netbeans POM projekt) for cleaning alone. 我最终制作了一个单独的模块(Netbeans POM projekt),可以单独清洁。 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". 问题的根源在于,您试图使Maven做一些与Maven的多模块“约定”相矛盾的事情,并且与Maven对“目标目录”的“理解”相抵触。 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. Maven的反应堆按其操作方式运行是有原因的,它是为了保留Maven的“精神”(或“惯例”),即在多模块构建中如何构造模块。

In Maven, the target directory is supposed to belong only to one project: each project has its own target directory. 在Maven中, target目录应该仅属于一个项目:每个项目都有自己的target目录。 In your scenario, there should really be a different target directory for app , module1 and module2 . 在您的方案中,应为appmodule1module2确实存在一个不同的target目录。

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 ). module1将自己的JAR输出到其自己的target目录( module1/target )中。
  2. Have module2 output its own JAR into its own target directory ( module2/target ). module2将自己的JAR输出到自己的target目录( 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. app (父模块)添加一个插件,该插件会将需要的东西从module1/targetmodule2/target收集到app/target ,并对这些工件进行任何处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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