简体   繁体   English

具有相互依赖关系的多模块Maven项目?

[英]Multimodule Maven Project with interdependencies?

I have a top-level maven project with submodules. 我有一个带有子模块的顶级Maven项目。 The first submodule is a Java project which generates some JavaScript library code from the compiler's annotation processor. 第一个子模块是一个Java项目,该项目从编译器的注释处理器生成一些JavaScript库代码。 I want to include those generated JS files into the second submodule, a webpack NPM managed project, for the build and then publish the webpack BACK into the first submodule before packaging into a fat-jar. 我想将那些生成的JS文件包含到第二个子模块(一个由webpack NPM管理的项目)中进行构建,然后将Webpack BACK发布到第一个子模块中,然后再打包到一个胖子容器中。 Does anyone know of a way to accomplish this? 有人知道实现此目标的方法吗?

What you describe is a circular dependency. 您描述的是循环依赖。 You have to break this circular dependency. 您必须打破这种循环依赖关系。 (You probably do similar things in your code all the time.) (您可能一直在代码中执行类似的操作。)

I have solved the same problem by breaking up the Java project. 我已经通过分解Java项目解决了相同的问题。 Once you do that you will recognize that, in fact, your first project was serving two separate roles that then become separated: 完成此操作后,您将认识到,实际上,您的第一个项目是担任两个单独的角色,然后又分开了:

From: 从:

  1. Java project with code and assembly 带有代码和汇编的Java项目
  2. JavaScript project JavaScript项目

To: 至:

  1. Java project with code 带有代码的Java项目
  2. JavaScript project JavaScript项目
  3. JAR-packaged project with assembly 带有组装的JAR打包项目

I've often seen this happen in multi-module projects that build into a WAR file, and I've adopted the rule of thumb that the WAR project should not have any Java (production) code, acknowledging its role as the aggregator/assembler. 我经常在内置到WAR文件中的多模块项目中看到这种情况,并且我采纳了经验法则,即WAR项目不应包含任何Java(生产)代码,并承认其作为聚合器/汇编器的作用。

Some folks will think this third project is frivolous, some always argue that you're easily getting too many Maven modules. 有些人会认为这第三个项目很琐碎,有些人总是认为您很容易获得太多的Maven模块。 I think that often stems from tooling or build pipeline limitations, once you break through those, you can just embrace a growing number of Maven modules, given that the boundaries are chosen well, and I see no problems here. 我认为这通常源于工具或构建管道的限制,一旦突破这些限制,您就可以接受越来越多的Maven模块,前提是边界选择得当,在这里我认为没有问题。

One hesitation, though: why is the JavaScript project separate to begin with? 犹豫不决:为什么JavaScript项目要从一开始就分开? If it is not deployed separately (evidently it isn't since you're assembling the "fat-jar"), the JavaScript code is following the delivery lifecycle of the "fat-jar", which would benefit from being in the same source repository, so why even make it a separate Maven module? 如果未单独部署(显然不是因为您正在组装“胖罐”,则不是),那么JavaScript代码将遵循“胖罐”的交付生命周期,这将受益于同一来源仓库,那么为什么还要使其成为一个单独的Maven模块呢? (If they were in separate source repositories, there's a cost in version management between the modules that I'm unsure you have reasons for.) There's no shame in having a monolith (if done well -- it happens, microservices make you believe otherwise, but in that world you'd probably deploy the JavaScript code separately anyway). (如果它们在单独的源代码存储库中,则我不确定您有理由在模块之间进行版本管理,这是有代价的。)拥有一个整体没有什么可耻的(如果做得好-碰巧的是,微服务使您相信其他情况) ,但是在那种情况下,您可能还是会分别部署JavaScript代码)。

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

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