{"id":904,"date":"2025-11-23T01:32:24","date_gmt":"2025-11-23T01:32:24","guid":{"rendered":"https:\/\/choudhury.com\/blog\/?p=904"},"modified":"2025-11-23T01:32:24","modified_gmt":"2025-11-23T01:32:24","slug":"maven-build-cache-extension","status":"publish","type":"post","link":"https:\/\/choudhury.com\/blog\/2025\/11\/23\/maven-build-cache-extension\/","title":{"rendered":"Maven Build Cache Extension"},"content":{"rendered":"<p>One of the advantages <a href=\"https:\/\/gradle.org\/\">Gradle<\/a> had over <a href=\"https:\/\/maven.apache.org\/\">Maven<\/a> was build caching.<\/p>\n<p>Thanks to <a href=\"https:\/\/maven.apache.org\/extensions\/maven-build-cache-extension\/\">Maven Cache Build Extension\u00a0<\/a> you can also get build caching for maven builds too.<\/p>\n<p>How to set this up<\/p>\n<p>On the top level of your maven project add<\/p>\n<p>.mvn folder<\/p>\n<p>Within the mvn folder add <strong>extensions.xml<\/strong>\u00a0 and <strong>maven-build-cache-config.xml<\/strong><\/p>\n<p>Example<\/p>\n<p><a href=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/folder-setup.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-906\" src=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/folder-setup.png\" alt=\"\" width=\"345\" height=\"204\" srcset=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/folder-setup.png 345w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/folder-setup-300x177.png 300w\" sizes=\"auto, (max-width: 345px) 100vw, 345px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>The contents of <strong>extensions.xml<\/strong> should be something like this<\/p>\n<div>\n<pre>&lt;extensions&gt;\r\n    &lt;extension&gt;\r\n        &lt;groupId&gt;org.apache.maven.extensions&lt;\/groupId&gt;\r\n        &lt;artifactId&gt;maven-build-cache-extension&lt;\/artifactId&gt;\r\n        &lt;version&gt;1.2.1&lt;\/version&gt;\r\n    &lt;\/extension&gt;\r\n&lt;\/extensions&gt;<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>The contents of\u00a0 maven-build-cache-config.xml should be like this from the template provided by in this\u00a0 In the<a href=\"https:\/\/maven.apache.org\/extensions\/maven-build-cache-extension\/\"> Getting Started page for Maven Build Cache Extension\u00a0<\/a><\/p>\n<p>(link for the template config can be found here)<\/p>\n<p><a href=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/maven-build-cache-config-xml-template-link.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-907\" src=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/maven-build-cache-config-xml-template-link.png\" alt=\"\" width=\"1355\" height=\"177\" srcset=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/maven-build-cache-config-xml-template-link.png 1355w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/maven-build-cache-config-xml-template-link-300x39.png 300w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/maven-build-cache-config-xml-template-link-1024x134.png 1024w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/maven-build-cache-config-xml-template-link-768x100.png 768w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><\/a><\/p>\n<p><strong>Note<\/strong> the default config has remote enabled, which is annoying default if you just want to get local build cache working first.<\/p>\n<p>So here are few adjustments I made to the template maven-build-cache-config.xml<\/p>\n<p>(yellow commented out ,\u00a0 green additional config added)<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/changes-to-build-build-cache-config-part1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-908\" src=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/changes-to-build-build-cache-config-part1.jpg\" alt=\"\" width=\"1047\" height=\"507\" srcset=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/changes-to-build-build-cache-config-part1.jpg 1047w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/changes-to-build-build-cache-config-part1-300x145.jpg 300w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/changes-to-build-build-cache-config-part1-1024x496.jpg 1024w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/changes-to-build-build-cache-config-part1-768x372.jpg 768w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><\/a><\/p>\n<p>Also for slimplicity I also comment out the global section with in the input section of the template<\/p>\n<p><a href=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/changes-to-build-build-cache-config-part2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-910\" src=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/changes-to-build-build-cache-config-part2.png\" alt=\"\" width=\"1977\" height=\"577\" srcset=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/changes-to-build-build-cache-config-part2.png 1977w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/changes-to-build-build-cache-config-part2-300x88.png 300w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/changes-to-build-build-cache-config-part2-1024x299.png 1024w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/changes-to-build-build-cache-config-part2-768x224.png 768w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/changes-to-build-build-cache-config-part2-1536x448.png 1536w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Now when you run your maven build (the second time), you should see it skipping various plugins as it uses the cached results instead<\/p>\n<p><a href=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/cached-build-output.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-911\" src=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/cached-build-output.png\" alt=\"\" width=\"1121\" height=\"250\" srcset=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/cached-build-output.png 1121w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/cached-build-output-300x67.png 300w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/cached-build-output-1024x228.png 1024w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/cached-build-output-768x171.png 768w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Where is the cached build stored?\u00a0 By default in the same folder your your m2 repository resides<\/p>\n<p><a href=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/build-cache-folder.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-912\" src=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2025\/11\/build-cache-folder.png\" alt=\"\" width=\"236\" height=\"165\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the advantages Gradle had over Maven was build caching. Thanks to Maven Cache Build Extension\u00a0 you can also get build caching for maven builds too. How to set this up On the top level of your maven project add .mvn folder Within the mvn folder add extensions.xml\u00a0 and maven-build-cache-config.xml Example &nbsp; The contents &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/choudhury.com\/blog\/2025\/11\/23\/maven-build-cache-extension\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Maven Build Cache Extension&#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":[3,9],"tags":[20,26],"class_list":["post-904","post","type-post","status-publish","format-standard","hentry","category-java","category-maven","tag-java","tag-maven"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/posts\/904","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=904"}],"version-history":[{"count":4,"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/posts\/904\/revisions"}],"predecessor-version":[{"id":915,"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/posts\/904\/revisions\/915"}],"wp:attachment":[{"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/media?parent=904"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/categories?post=904"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/tags?post=904"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}