Having a maven project build its own dependencies?

前端 未结 7 2212
故里飘歌
故里飘歌 2021-02-13 03:40

With maven is it possible to have a top-level project who\'s packaging type is \"war\" which will build itself and all of its dependent modules (packaged as jar) and have the bu

7条回答
  •  悲&欢浪女
    2021-02-13 04:25

    When you have a multi-module project and you're doing work in several modules simultaneously it can be tedious and error-prone to make sure all the necessary dependencies are updated.

    In my situation, I would like my build system to detect changes and only build the modules that are necessary. One way this might be possible with maven is for someone to write a custom plugin that does this, which doesn't seem insurmountable given there are already complex plugins available, like the maven release plugin.

    Others have already mentioned the aggregation pom concept, which is repeatable and does produce the necessary artifacts. But sometimes you end up building more than you really need to.

    Maven profiles can help and here's a good article in that regard:

    Using Aggregate and Parent POMs

    Also note in the article the concept of the batch pom, which I was not previously aware of.

    Remember, mvn clean install will push your artifact into your local repo. So if module A depends on module B, as long as your local repo has the latest build of module B then you should be all set. So, if there were an external tool that was watching for changes to module B and automatically built it when there were and pushed those changes into the local repo then when module A was rebuilt it would pick up those changes. There are continuous integration (CI) tools that can do this, like Jenkins. But you would need a local install to have this work directly with your local repo. It's still an option, though.

    Another option would be for the CI environment to push your builds to an external maven repo (or even one you setup locally with something like Nexus). Then you setup your CI builds to pull from that location as well.

    So, there are solutions that rely on other tools or potential plugins to do what you want - just depends how much time and effort you want to invest to get it all setup. But, once you get over that hurdle you'll have a system (and knowledge and experience) that you can use on all your projects, not to mention you'll be familiar with how many development shops/teams work.

    I would recommend researching continuous integration and continuous delivery for more information and ideas.

提交回复
热议问题