{"id":1799,"date":"2017-10-10T21:17:56","date_gmt":"2017-10-10T21:17:56","guid":{"rendered":"http:\/\/blog.paranoidprofessor.com\/?p=1799"},"modified":"2017-10-10T21:17:56","modified_gmt":"2017-10-10T21:17:56","slug":"maven-the-alternative-build-tool","status":"publish","type":"post","link":"https:\/\/blog.paranoidprofessor.com\/index.php\/2017\/10\/10\/maven-the-alternative-build-tool\/","title":{"rendered":"Maven the alternative build tool"},"content":{"rendered":"<h2>Why maven<\/h2>\n<p><a href=\"https:\/\/maven.apache.org\/\">Maven<\/a> is a tool for building software. Doesn&#8217;t there already exist a number of tools for doing this exact task?\u00a0 Two different tools that do this\u00a0are the classic <a href=\"https:\/\/www.gnu.org\/software\/make\/\">make utility <\/a>or the much newer\u00a0<a href=\"http:\/\/ant.apache.org\/\">Apache Ant<\/a>.<\/p>\n<p>The make utility requires a script that defines all of the objects and their dependencies. Make forces you to define every object and their dependencies. \u00a0That is a bit of a harsh analysis of the make tool as it is possible to create more generic rules for compiling objects from source but in general this is accurate description of make.<\/p>\n<p>Apache Ant is a few more steps along the automation path from make. \u00a0You define some of the targets and a few rules in your build.xml file for compiling code, making jar files or other general commands. \u00a0There is no default defined directory structure for the source files or external libraries. \u00a0You need to define the structure each time you create a new program.<\/p>\n<p>Maven has a number of differences from other build tools. \u00a0There is a very specific directory structure for each of the types of programs or objects that Maven can build. \u00a0In addition to the actual directory structure Maven has the concept of a the software lifecycle for the objects it builds.<\/p>\n<p>Maven will perform all the steps in the lifecycle from the start up until the phase that you select.<\/p>\n<ul>\n<li>validate &#8211; perform a check to ensure that all the necessary files are available.<\/li>\n<li>compile &#8211; compile the source code of the project.<\/li>\n<li>test &#8211; runs the unit tests that have been defined.<\/li>\n<li>package &#8211; create the final package for the code. \u00a0This might be a JAR, WAR\u00a0or EAR\u00a0file.<\/li>\n<li>install &#8211; install the package into the local repository.<\/li>\n<li>deploy &#8211; install the package into the remote repository.<\/li>\n<\/ul>\n<p>Thus the program is compiled before it is tested and tested before it is packaged.<\/p>\n<p>It is possible to setup a similar flow using Apache Ant but then you are responsible to create lifecycle from scratch. \u00a0This includes adding additional logic for doing testing and implementing logic for installing the compiled objects.<\/p>\n<p>In addition to all the other built-in logic that Maven contains it also is well aware of the different types of output objects\u00a0such as jar or war files.<\/p>\n<h2>Maven Repositories<\/h2>\n<p>Another major difference between these other tools is that Maven has its own repository of\u00a0jar files and other artifacts that might be needed when building objects. \u00a0Maven can\u00a0store multiple versions of the various artifacts in its repository.<\/p>\n<p>The central repository is full of all sorts of open source jar files so it is quite possible that if your project uses one of these jars (ie log4j) then it will already be available. \u00a0You simply add your required dependency and it will be downloaded to your computer and used on the next build.<\/p>\n<p>Each object in the repository is defined by the unique combination of three different keys.<\/p>\n<ul>\n<li>groupId<\/li>\n<li>artifactId<\/li>\n<li>version<\/li>\n<\/ul>\n<p>The combination of these three keys creates a unique value that refers to the object specifically. \u00a0This built in repository concept actually really simplifies dealing with libraries if you only need open source libs.<\/p>\n<p>Of course it is also possible to add other third party libraries. \u00a0Using libraries that are not already in the repository is a bit different and will be described\u00a0later.<\/p>\n<h2>Projects and project structures<\/h2>\n<p>One of the advantages to Maven is the structure that it provides. \u00a0Maven contains a lot of templates and standard directory structures. \u00a0There is a structure available if you simply need to create a java jar file but there is also a template if you want to create restful web applications.<\/p>\n<p>Of course, it is possible to create these directory structures manually but another feature of Maven is that you simply pick which type of project you wish and it will create the entire directory structure for you.<\/p>\n<h2>Testing your work<\/h2>\n<p>It goes without saying that providing unit tests would be both a best practice and\u00a0is easy enough to do if\u00a0you start at the beginning. \u00a0Performing the unit tests is part of the lifecycle and because they are run before creating any packages it should help to guarantee a higher quality of program.<\/p>\n<h2>Summary<\/h2>\n<p>Maven is a enterprise quality build tool that supports more than just the generation of programs or libraries.<\/p>\n<p>Maven is big but I will attempt to describe some of the basics for anyone who wishes to expand their tool set to include it.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Why maven Maven is a tool for building software. Doesn&#8217;t there already exist a number of tools for doing this exact task?\u00a0 Two different tools that do this\u00a0are the classic make utility or the much newer\u00a0Apache Ant. The make utility &hellip; <a href=\"https:\/\/blog.paranoidprofessor.com\/index.php\/2017\/10\/10\/maven-the-alternative-build-tool\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[20],"tags":[73,12],"_links":{"self":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts\/1799"}],"collection":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/comments?post=1799"}],"version-history":[{"count":12,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts\/1799\/revisions"}],"predecessor-version":[{"id":2644,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts\/1799\/revisions\/2644"}],"wp:attachment":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/media?parent=1799"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/categories?post=1799"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/tags?post=1799"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}