0

In a project I'm working on, we auto generate the interfaces API in a folder called api/ which contains several sub-folders, where each of them has a pom file able to compile the content of the module.

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

Basically the pom.xml triggers the code generator which then generates all the api/* modules. By the time I run maven clean install within the folder build/, the api folder is empty, because it will be filled by the code generator in the generate-code Maven phase.

Is there a way to tell the build/pom.xml to handle the modules inside api (the names are known) within the same build?

If I specify a <module> which does not exist, maven verify will complain.

Thanks

slux83
  • 686
  • 9
  • 20

2 Answers2

1

I believe the resolution depends on flexibility of the API's list

  • if the list of API-modules is dynamic, it's simply not possible to declare a dependency on a particular module - nobody knows them in advance. I would consider generation of source folders and adding them to a single module. As the result, you'll have single all-in-one module, which will contain all generated and compiled code. Other projects can use it as dependency
  • if the list of API-modules is fixed, their POM files, which declare GAVs, should not be generated. Then other projects can use any of them as dependencies, although their code is generated only during the build
Viktor
  • 345
  • 1
  • 3
  • 13
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".

  • I didn't really understand your point. Maybe was not clear in the post, but we always generate all the apis from a UML model. It means that when we call maven clean install from the build folder, the code generator is triggered in the generate-code phases and only after it, the modules will be ready to be used. – slux83 Jun 08 '15 at 14:24
  • 1
    Hm maybe I didnt make myself clear. I think you are taking a path which makes life unnecessary hard for you. If you are trying to generate and built Projects dynamically you'll at least always have Problems with all Projects needing a reference to those.(like your aggregate Project or any client-Project). My Suggestion is to just create the Projects(generated or not doesnt matter), install and use them as usual. So dont mix the Project creation part with the build process, it will give you serious Trouble and little in return. – Tobias Maslowski Jun 09 '15 at 11:12