{"id":805,"date":"2021-09-04T23:49:20","date_gmt":"2021-09-04T23:49:20","guid":{"rendered":"https:\/\/choudhury.com\/blog\/?p=805"},"modified":"2021-09-04T23:49:23","modified_gmt":"2021-09-04T23:49:23","slug":"maven-enforcer-plugin","status":"publish","type":"post","link":"https:\/\/choudhury.com\/blog\/2021\/09\/04\/maven-enforcer-plugin\/","title":{"rendered":"Maven Enforcer Plugin"},"content":{"rendered":"\n<p>The <a href=\"https:\/\/maven.apache.org\/enforcer\/maven-enforcer-plugin\/\" data-type=\"URL\" data-id=\"https:\/\/maven.apache.org\/enforcer\/maven-enforcer-plugin\/\">maven-enforcer-plugin<\/a> (and it&#8217;s various extensions) are really useful if you want to enforce various build rules such as :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><span style=\"font-size: 1rem;\">Make sure the maven build is using minimum required Java and Maven versions.<\/span><\/li><li>Build is not referring to snapshot dependencies<\/li><li>No Duplicate classes in your project dependencies (see screenshot below of what it reports when it finds duplicates)<\/li><li>Ban certain imports (e.g. java.util.Vector,  java.util.Date etc)  being used in your build.<\/li><\/ul>\n\n\n\n<p>Here is an <a href=\"https:\/\/github.com\/muminc\/maven-enforcer-example\" data-type=\"URL\" data-id=\"https:\/\/github.com\/muminc\/maven-enforcer-example\">example project <\/a>to show above checks in action.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Output of BanDuplicateClasses check if it detects duplicate classes.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2021\/09\/image-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"661\" src=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2021\/09\/image-1-1024x661.png\" alt=\"\" class=\"wp-image-807\" srcset=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2021\/09\/image-1-1024x661.png 1024w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2021\/09\/image-1-300x194.png 300w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2021\/09\/image-1-768x496.png 768w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2021\/09\/image-1.png 1066w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Output of RestrictImports if finds usage of Banned Import (example: java.util.Vector).<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2021\/09\/image-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"374\" src=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2021\/09\/image-2-1024x374.png\" alt=\"\" class=\"wp-image-808\" srcset=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2021\/09\/image-2-1024x374.png 1024w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2021\/09\/image-2-300x110.png 300w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2021\/09\/image-2-768x281.png 768w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2021\/09\/image-2-1536x562.png 1536w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2021\/09\/image-2-2048x749.png 2048w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>The maven-enforcer-plugin (and it&#8217;s various extensions) are really useful if you want to enforce various build rules such as : Make sure the maven build is using minimum required Java and Maven versions. Build is not referring to snapshot dependencies No Duplicate classes in your project dependencies (see screenshot below of what it reports when &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/choudhury.com\/blog\/2021\/09\/04\/maven-enforcer-plugin\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Maven Enforcer Plugin&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6,3,9],"tags":[],"class_list":["post-805","post","type-post","status-publish","format-standard","hentry","category-code-quality","category-java","category-maven"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/posts\/805","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/comments?post=805"}],"version-history":[{"count":3,"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/posts\/805\/revisions"}],"predecessor-version":[{"id":810,"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/posts\/805\/revisions\/810"}],"wp:attachment":[{"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/media?parent=805"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/categories?post=805"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/tags?post=805"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}