![]() This means that if a parent project uses a variable, then its definition in the child, not the parent, will be the one eventually used. One factor to note is that these variables are processed after inheritance as outlined above. Given the previous original artifact POMs again, Specify in the parent POM the directories of its modules (children POMs).Change the parent POMs packaging to the value "pom".Specify in every child POM who their parent POM is.You'd just have to apply all three rules: Meaning, you can have your modules specify a parent project, and at the same time, have that parent project specify those Maven projects as its modules. By doing so, you'd only have to build the parent and the rest will follow.īut of course, you can have both Project Inheritance and Project Aggregation. Thus, all you have to do is to let your Maven projects inherit that parent project, and those configurations would then be applied to all of them.Īnd if you have a group of projects that are built or processed together, you can create a parent project and have that parent project declare those projects as its modules. If you have several Maven projects, and they all have similar configurations, you can refactor your projects by pulling out those similar configurations and making a parent project. Project Inheritance vs Project Aggregation Given the previous original artifact POMs and directory structure: To do Project Aggregation, you must do the following: By doing so, the parent project now knows its modules, and if a Maven command is invoked against the parent project, that Maven command will then be executed to the parent's modules as well. But instead of specifying the parent POM from the module, it specifies the modules from the parent POM. Project Aggregation is similar to Project Inheritance. And let us introduce another artifact, :my-module:1.Īs the name suggests, it's the relative path from the module's pom.xml to the parent's pom.xml. Example 1 The ScenarioĪs an example, let us reuse our previous artifact, :my-app:1. The Super POM is one example of project inheritance, however you can also introduce your own parent POMs by specifying the parent element in the POM, as demonstrated in the following examples. Therefore when Maven sees the dependencies in the minimal POM, it would know that these dependencies will be downloaded from which was specified in the Super POM.Įlements in the POM that are merged are the following: If you build your project using the minimal POM, it would inherit the repositories configuration in the Super POM. If it is not specified in the POM, then the default value "jar" would be used.įurthermore, you can see that in the minimal POM the repositories were not specified. Every Maven project has a packaging type. One of these default values is the packaging type. As for the example above, its fully qualified artifact name is ":my-app:1".Īlso, as mentioned in the first section, if the configuration details are not specified, Maven will use their defaults. These three values form the project's fully qualified artifact name. version - the version of the artifact under the specified groupĪ POM requires that its groupId, artifactId, and version be configured.artifactId - the id of the artifact (project).groupId - the id of the project's group.The minimum requirement for a POM are the following: You can see the Super POM for Maven 3.6.3 in Maven Core reference documentation. All POMs extend the Super POM unless explicitly set, meaning the configuration specified in the Super POM is inherited by the POMs you created for your projects. Other information such as the project version, description, developers, mailing lists and such can also be specified. Some of the configuration that can be specified in the POM are the project dependencies, the plugins or goals that can be executed, the build profiles, and so on. It reads the POM, gets the needed configuration information, then executes the goal. When executing a task or goal, Maven looks for the POM in the current directory. Examples for this is the build directory, which is target the source directory, which is src/main/java the test source directory, which is src/test/java and so on. It contains default values for most projects. It is an XML file that contains information about the project and configuration details used by Maven to build the project. Project Inheritance vs Project AggregationĪ Project Object Model or POM is the fundamental unit of work in Maven.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |