{"id":12608,"date":"2021-02-19T12:05:34","date_gmt":"2021-02-19T17:05:34","guid":{"rendered":"http:\/\/jianmingli.com\/wp\/?p=12608"},"modified":"2021-02-19T12:05:34","modified_gmt":"2021-02-19T17:05:34","slug":"maven-pom-hierarchy","status":"publish","type":"post","link":"https:\/\/jianmingli.com\/wp\/?p=12608","title":{"rendered":"Maven POM Hierarchy"},"content":{"rendered":"<div class='toc wptoc'>\n<h2>Contents<\/h2>\n<ol class='toc-odd level-1'>\n\t<li>\n\t\t<a href=\"#Overview\">Overview<\/a>\n\t<\/li>\n\t<li>\n\t\t<a href=\"#Project_Inheritance\">Project Inheritance<\/a>\n\t\t<ol class='toc-even level-2'>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Super_POM\">Super POM<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Minimal_POM\">Minimal POM<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Parent_POM\">Parent POM<\/a>\n\t\t\t<\/li>\n\t\t<\/ol>\n\t<li>\n\t\t<a href=\"#Project_Aggregation\">Project Aggregation<\/a>\n\t\t<ol class='toc-even level-2'>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Parent_POM_with_Aggregation\">Parent POM with Aggregation<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Project_Model_Variables\">Project Model Variables<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Project_Properties\">Project Properties<\/a>\n\t\t\t<\/li>\n\t\t<\/ol>\n\t<li>\n\t\t<a href=\"#References\">References<\/a>\n\t<\/li>\n<\/ol>\n<\/ol>\n<\/div>\n<div class='wptoc-end'>&nbsp;<\/div>\n<span id=\"Overview\"><h2>Overview<\/h2><\/span>\n<p>* POM: project object model<br \/>\n* POM is an xml file<br \/>\n* Used to build a project<\/p>\n<span id=\"Project_Inheritance\"><h2>Project Inheritance<\/h2><\/span>\n<p>* Following elements in POM are merged:<br \/>\n&#8211; dependencies<br \/>\n&#8211; developers and contributors<br \/>\n&#8211; plugin lists (including reports)<br \/>\n&#8211; plugin executions with matching ids<br \/>\n&#8211; plugin configuration<br \/>\n&#8211; resources<\/p>\n<span id=\"Super_POM\"><h3>Super POM<\/h3><\/span>\n<p>* All POMs extends the super POM<br \/>\n* Default package: jar<br \/>\n* Default repository is central repository: https:\/\/repo1.maven.org\/maven2\/<\/p>\n<span id=\"Minimal_POM\"><h3>Minimal POM<\/h3><\/span>\n<p>* Mandatory elements:<\/p>\n<pre lang=\"xml\">\r\n<project>\r\n  <modelVersion>4.0.0<\/modelVersion>\r\n \r\n  <groupId>com.mycompany.app<\/groupId>\r\n  <artifactId>my-app<\/artifactId>\r\n  <version>1<\/version>\r\n<\/project>\r\n<\/pre>\n<p>* Other elements inherit from super POM<\/p>\n<span id=\"Parent_POM\"><h3>Parent POM<\/h3><\/span>\n<p>* Specify parent pom:<\/p>\n<pre lang=\"xml\">\r\n<project>\r\n  <modelVersion>4.0.0<\/modelVersion>\r\n  <!-- can be omitted if same as parent -->\r\n  <groupId>com.mycompany.app<\/groupId>\r\n  <version>1<\/version>\r\n  <!-- end -->\r\n \r\n  <parent>\r\n    <groupId>com.mycompany.app<\/groupId>\r\n    <artifactId>my-app<\/artifactId>\r\n    <version>1<\/version>\r\n\t<!-- if parent pom not in the dir one level above\r\n    <relativePath>..\/parent\/pom.xml<\/relativePath>\r\n\t-->\r\n  <\/parent>\r\n  \r\n  <artifactId>my-module<\/artifactId>\r\n<\/project>\r\n<\/pre>\n<span id=\"Project_Aggregation\"><h2>Project Aggregation<\/h2><\/span>\n<p>* Set packaging to: pom<br \/>\n* Specify child POMs as modules:<\/p>\n<pre lang=\"xml\">\r\n<project>\r\n  <modelVersion>4.0.0<\/modelVersion>\r\n \r\n  <groupId>com.mycompany.app<\/groupId>\r\n  <artifactId>my-app<\/artifactId>\r\n  <version>1<\/version>\r\n  <packaging>pom<\/packaging>\r\n \r\n  <modules>\r\n    <module>my-module<\/module>\r\n  <\/modules>\r\n<\/project>\r\n<\/pre>\n<span id=\"Parent_POM_with_Aggregation\"><h3>Parent POM with Aggregation<\/h3><\/span>\n<p>* You can specify parent pom to also include modules:<\/p>\n<pre lang=\"xml\">\r\n<project>\r\n  <modelVersion>4.0.0<\/modelVersion>\r\n \r\n  <groupId>com.mycompany.app<\/groupId>\r\n  <artifactId>my-app<\/artifactId>\r\n  <version>1<\/version>\r\n  <packaging>pom<\/packaging>\r\n \r\n  <modules>\r\n    <module>my-module<\/module>\r\n  <\/modules>\r\n<\/project>\r\n<\/pre>\n<p>* Child POM:<\/p>\n<pre lang=\"xml\">\r\n<project>\r\n  <modelVersion>4.0.0<\/modelVersion>\r\n \r\n  <parent>\r\n    <groupId>com.mycompany.app<\/groupId>\r\n    <artifactId>my-app<\/artifactId>\r\n    <version>1<\/version>\r\n    <relativePath>pom.xml<\/relativePath>\r\n  <\/parent>\r\n \r\n  <artifactId>my-module<\/artifactId>\r\n<\/project>\r\n<\/pre>\n<span id=\"Project_Model_Variables\"><h3>Project Model Variables<\/h3><\/span>\n<p>* Variable values defined in child POM take precedence over parent values<br \/>\n* Project model variables<br \/>\n&#8211; any single value element can be referenced as a variable, e.g.:<\/p>\n<pre lang=\"xml\">\r\n${project.groupId}\r\n${project.version}\r\n${project.build.sourceDirectory}\r\n${project.basedir}\r\n${project.baseUri}\r\n${maven.build.timestamp}\r\n<\/pre>\n<span id=\"Project_Properties\"><h3>Project Properties<\/h3><\/span>\n<p>* Any properties defined in project can be referenced as a variable:<\/p>\n<pre lang=\"xml\">\r\n  <properties>\r\n    <maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss'Z'<\/maven.build.timestamp.format>\r\n  <\/properties>\r\n<\/pre>\n<span id=\"References\"><h2>References<\/h2><\/span>\n<p>* <a href='https:\/\/maven.apache.org\/guides\/introduction\/introduction-to-the-pom.html'>Introduction to the POM<\/a><br \/>\n* <a href='https:\/\/maven.apache.org\/pom.html'>POM Reference<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview * POM: project object model * POM is an xml file * Used to build a project Project Inheritance * Following elements in POM are merged: &#8211; dependencies &#8211; developers and contributors &#8211; plugin lists (including reports) &#8211; plugin &hellip; <a href=\"https:\/\/jianmingli.com\/wp\/?p=12608\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[135],"tags":[605],"class_list":["post-12608","post","type-post","status-publish","format-standard","hentry","category-maven-lang","tag-maven"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8cRUO-3hm","_links":{"self":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/12608","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12608"}],"version-history":[{"count":1,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/12608\/revisions"}],"predecessor-version":[{"id":12609,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/12608\/revisions\/12609"}],"wp:attachment":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12608"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12608"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12608"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}