slux83
slux83

Reputation: 706

How to tell Maven to compile auto-generated maven modules?

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

Upvotes: 0

Views: 1263

Answers (2)

Viktor
Viktor

Reputation: 365

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

Upvotes: 1

Tobias Maslowski
Tobias Maslowski

Reputation: 41

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".

Upvotes: 0

Related Questions