YouTip LogoYouTip

Maven Build Automation

Automated build defines a scenario where, after a project is successfully built, its related dependent projects begin their build process. This ensures the stability of the dependent projects. For example, a team is developing a project called `bus-core-api`, and there are two other projects, `app-web-ui` and `app-desktop-ui`, that depend on it. The `app-web-ui` project uses the 1.0 snapshot of the `bus-core-api` project: 4.0.0app-web-uiapp-web-ui1.0jarbus-core-apibus-core-api1.0-SNAPSHOT The `app-desktop-ui` project uses the 1.0 snapshot of the `bus-core-api` project: 4.0.0app-desktop-uiapp-desktop-ui1.0jarbus-core-apibus-core-api1.0-SNAPSHOT The `bus-core-api` project: 4.0.0bus-core-apibus-core-api1.0-SNAPSHOTjar Now, the teams for the `app-web-ui` and `app-desktop-ui` projects require that their build processes should be triggered whenever the `bus-core-api` project changes. Using snapshots ensures that the latest `bus-core-api` project is used, but to meet the above requirement, we need to do some additional work. Two approaches can be used: * Add a post-build goal in the `bus-core-api` project's POM file to trigger the builds of the `app-web-ui` and `app-desktop-ui` projects. * Use a Continuous Integration (CI) server, such as Hudson, to manage the build automation automatically. * * * ## Using Maven Modify the `pom.xml` file of the `bus-core-api` project. 4.0.0bus-core-apibus-core-api1.0-SNAPSHOTjarmaven-invoker-plugin1.6trueapp-web-ui/pom.xmlapp-desktop-ui/pom.xmlbuildrun Open a command console, navigate to the `C: > MVN > bus-core-api` directory, and execute the following command. C:MVNbus-core-api>mvn clean package -U After the command is executed, Maven will start building the `bus-core-api` project. Scanning for projects... ------------------------------------------------------------------ Building bus-core-api task-segment: [clean, package] ------------------------------------------------------------------... [jar:jar {execution: default-jar}] Building jar: C:MVNbus-core-uitarget bus-core-ui-1.0-SNAPSHOT.jar ------------------------------------------------------------------ BUILD SUCCESSFUL ------------------------------------------------------------------ After the `bus-core-api` is built successfully, Maven will start building the `app-web-ui` project. ------------------------------------------------------------------ Building app-web-ui task-segment: ------------------------------------------------------------------... [jar:jar {execution: default-jar}] Building jar: C:MVNapp-web-uitarget app-web-ui-1.0-SNAPSHOT.jar ------------------------------------------------------------------ BUILD SUCCESSFUL ------------------------------------------------------------------ After the `app-web-ui` is built successfully, Maven will start building the `app-desktop-ui` project. ------------------------------------------------------------------ Building app-desktop-ui task-segment: ------------------------------------------------------------------... [jar:jar {execution: default-jar}] Building jar: C:MVNapp-desktop-uitarget app-desktop-ui-1.0-SNAPSHOT.jar ------------------------------------------------------------------- BUILD SUCCESSFUL ------------------------------------------------------------------- * * * ## Using a Continuous Integration Server (CI) If a CI server is used, developers do not need to update the `bus-core-api` project's POM every time a new project, for example `app-mobile-ui` in this instance, is added as a dependency to `bus-core-api`. Hudson will leverage Maven's dependency management to automate the creation of the build. !(#) Hudson treats each project build as a task. After code for a project is committed to SVN (or any code management tool mapped to Hudson), Hudson will start the project's build task. Once this build task is completed, Hudson will automatically trigger the build tasks for other dependent projects (the builds of other dependent projects). In the example above, when the source code for `bus-core-ui` is updated in SVN, Hudson starts the project build. Once the build is successful, Hudson automatically finds the dependent projects and then starts building the `app-web-ui` and `app-desktop-ui` projects.
← Maven Deployment AutomationMaven Project Documents β†’