0

在我正在处理的一个项目中,我们在一个名为 api/ 的文件夹中自动生成接口 API,该文件夹包含几个子文件夹,其中每个文件夹都有一个能够编译模块内容的 pom 文件。

project-root
  - api
    - module-api-1
      - pom.xml
    - module-api-2
      - pom.xml
    - module-api-3
      - pom.xml
    - module-api-4
      - pom.xml
  - build
    - pom.xml

基本上 pom.xml 触发代码生成器,然后生成所有 api/* 模块。当我在 build/ 文件夹中运行 maven clean install 时,api 文件夹是空的,因为它将在 generate-code Maven 阶段由代码生成器填充。

有没有办法告诉 build/pom.xml 在同一个构建中处理 api 中的模块(名称已知)?

如果我指定一个<module>不存在的,maven verify 会抱怨。

谢谢

4

2 回答 2

1

我相信解决方案取决于 API 列表的灵活性

  • 如果 API 模块列表是动态的,则根本不可能声明对特定模块的依赖——没有人事先知道它们。我会考虑生成源文件夹并将它们添加到单个模块中。结果,您将拥有一个一体化模块,其中包含所有生成和编译的代码。其他项目可以使用它作为依赖
  • 如果 API 模块列表是固定的,则不应生成其声明 GAV 的 POM 文件。然后其他项目可以使用它们中的任何一个作为依赖项,尽管它们的代码仅在构建期间生成
于 2015-06-09T05:19:12.093 回答
0

If it was my Project, I would declare the references to the modules static in the pom (modules/ module-api-1 module-api-2 ...) and also have the module-Projects in a generated state so it theoretically could compile without generating the apis. So what I'm saying is - just treat these modules as full fledged module projects.

Then and I assume this is important for you, if you have a Change in the code that causes a Change in one or more apis, i would run the Generator. If you need to reflect this changed api in a repo, you can still just install the changed module.

I know this propably isnt what you wanted to do, but I'm pretty sure you'll have less Problems taking "the conservative way".

于 2015-06-08T12:04:38.030 回答