<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/"><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="https://mehmandarov.com/tag/software-development/feed.xml" rel="self" type="application/atom+xml"/><link href="https://mehmandarov.com/tag/software-development/" rel="alternate" type="text/html"/><updated>2017-12-01T07:23:00+01:00</updated><id>https://mehmandarov.com/tag/software-development/feed.xml</id><title type="html">Rustam Mehmandarov - tag: software development</title><subtitle type="text">Posts tagged &quot;software development&quot; on Rustam Mehmandarov.</subtitle><author><name>Rustam Mehmandarov</name></author><entry><title type="html">Escaping Developer Nightmares</title><link href="https://mehmandarov.com/escaping-developer-nigthmares/" rel="alternate" type="text/html" title="Escaping Developer Nightmares"/><published>2017-12-01T07:23:00+01:00</published><updated>2017-12-01T07:23:00+01:00</updated><id>https://mehmandarov.com/escaping-developer-nigthmares</id><content type="html" xml:base="https://mehmandarov.com/escaping-developer-nigthmares/"><![CDATA[<p><em>A short write up of the bad things we do in software development and some suggestions on how to fix them.</em></p>

<ul>
  <li><a href="#the-existing-state-of-affairs">The Existing State of Affairs</a></li>
  <li><a href="#the-moving-parts">The Moving Parts</a></li>
  <li><a href="#conclusion">Conclusion</a></li>
</ul>

<hr />

<p>Let&#8217;s take a look into what we can do to achieve a better development environment than an average development project &#8211; a project that most of us have seen at some point in our professional lives, or maybe even are a part of right now. We will also look into some tools and patterns that will help us convert those projects into a paradise for the developers.</p>

<p>Just a few decades ago, we were working in ways that might look like unproductive, in the best case. Our development models were predominated by waterfalls, our IDEs were basic and we were compiling our projects by hand, using <code class="language-plaintext highlighter-rouge">javac</code>, or building up the <code class="language-plaintext highlighter-rouge">CLASSPATH</code> depending on the <code class="language-plaintext highlighter-rouge">GOTO</code> statements in a huge spaghetti code contained in countless <code class="language-plaintext highlighter-rouge">bat</code> files. Our code lived in a very simple versioning systems that were not distributed or supported branching strategies that are praised by the developers today. Our documentation lived in <code class="language-plaintext highlighter-rouge">doc</code> files on shared network drives, side by side with the simple issue tracking systems, that don&#8217;t even get close to what we have today.</p>

<p>Today, it is all different &#8211; we have Git, real issue tracking, IDEs, all that integrated with build servers and collaborative platforms. Yes, everything is much better, more effective and user-friendly, one might think that we are in the paradise already? Well&#8230; yes, things are fortunately getting better, however, we are still doing things in a way that might still give you nightmares, several decades from now.</p>

<p>Last years I have been working and invited to evaluate and help with an audit of various projects. Here are some of my observations and thoughts.</p>

<h2 id="the-existing-state-of-affairs">The Existing State of Affairs</h2>

<p>This <a href="https://twitter.com/brianwisti/status/503987766032494592?lang=en">tweet</a> describes it pretty well:</p>

<figure class="highlight"><pre><code class="language-text" data-lang="text">YOU ARE IN A LEGACY CODEBASE
&gt; RUN TESTS
YOU HAVE NO TESTS
&gt; READ SPEC
YOU HAVE NO SPEC
&gt; WRITE FIX
YOU ARE EATEN BY AN ELDER CODE HACK.</code></pre></figure>

<p>Some of the issues are, naturally, remnants of the past &#8211; the legacy systems; but even those systems and most of the other problems we see today can be avoided if we slightly change our view at some of the main parts of the development process. In most of the cases, we would be aware of those issues, but we might need to explain and motivate the others &#8211; often people are responsible for the projects and those who prioritize the development and maintenance backlog.</p>

<h2 id="the-moving-parts">The Moving Parts</h2>

<p>The road to a great nightmare-free future consists of three components: the code quality, the development and build tools, and a good documentation and collaboration systems. When evaluating systems I often start asking some simple questions listed below to get an idea of the system.</p>

<h3 id="1-the-code">1. The Code</h3>
<h4 id="the-code-quality">The Code Quality</h4>

<p>First thing off is the general code quality. I often start by asking about simple things &#8211; if the project has a coding standard, and if it is being followed. I also ask to take a quick peek at the code and check minor things like file encodings and MIME types. I also follow up with a question if the team is practicing code reviews, and how they are doing that.</p>

<p>While those things alone don&#8217;t have to mean anything, and are minor issues individually, together with other factors they still are initial indicators of possible neglect. This gives me a possibility to map areas where to look further.</p>

<p>In addition to that, there are also some more specific parts that will be listed as sub-sections below.</p>

<h4 id="the-third-party-libraries">The third-party libraries</h4>
<p>The role of the third party libraries and their use is often forgotten and neglected when considering code and system quality. This is quite unfortunate as this is the part of the code that you might not be able to patch easily, and is harder to maintain compared to your own codebase. Here are some simple questions that might help with getting a better grip on third-party libraries:</p>

<ul>
  <li>Do you keep track of your third-party libraries?</li>
  <li>Do you regularly check if there are known issues or vulnerabilities in them?</li>
  <li>Do you have a plan for keeping them updated?</li>
  <li>Are the libraries you are using being actively maintained by the authors?</li>
  <li>Are the libraries you are using compatible with each other?</li>
  <li>Do the libraries you are using have appropriate licenses that are compatible with your system? <em>(This also applies to the open source software licenses.)</em></li>
</ul>

<p>Issues and vulnerabilities are being found and patched all the time. As an example for this, let me point to Google&#8217;s <a href="https://github.com/google/oss-fuzz">OSS-Fuzz Project</a> that has found <a href="https://testing.googleblog.com/2017/05/oss-fuzz-five-months-later-and.html">numerous security vulnerabilities</a> in several critical open source projects. Unfortunately, even though many people are aware of the security issues in software in general, the library updates still often tend to be forgotten.</p>

<p>It is also worth noting that while most of the issues on my list above are security related, the last one might be of a legal sort, and probably is the most neglected of the issues listed.</p>

<h4 id="the-architecture">The Architecture</h4>

<p>I am often being asked to assess a system and tell something about its architecture compared to more modern systems. The different aspects of the system&#8217;s architecture will tell a lot about its maintainability both when it comes to further development, bug fixing, and keeping the system running. Some questions that might help with determining the state of the system would be:</p>

<ul>
  <li>Does your architecture support automated deployment?</li>
  <li>Does your architecture support continuous deploy and delivery?</li>
  <li>Does your architecture support load balancing?</li>
  <li>Does your architecture support microservices?</li>
  <li>How is the architecture implemented in the code?</li>
</ul>

<h4 id="tools-for-maintaining-the-code-quality">Tools for Maintaining the Code Quality</h4>

<p>Some of this might sound familiar to you when you think of one or several systems you had been working with and you might now be wondering what you can do to improve the code quality? Further steps here would be starting to use proper tools that will be able to tell more about the various aspects of your code. Some of them can be used as plugins to your build system (like Maven), and some could be stand-alone tools.</p>

<p>Stand-alone tools for code analysis:</p>
<ul>
  <li><a href="https://www.sonarqube.org/">SonarQube</a></li>
  <li><a href="https://pmd.github.io/">PMD</a></li>
  <li><a href="http://findbugs.sourceforge.net/">FindBugs</a></li>
</ul>

<p>Maven plugins to consider (more about plugins in my <a href="/five-pillars-of-a-good-maven-project/">previous post</a>):</p>
<ul>
  <li>Assembly</li>
  <li>Versions</li>
  <li>Dependency</li>
  <li>Enforcer</li>
  <li>Surefire</li>
  <li>Failsafe</li>
  <li>Sonar</li>
  <li>Findbugs</li>
  <li>pmd</li>
</ul>

<p><em><strong>Bonus:</strong></em> See this post on <a href="/cmd-tools-for-developers/">command line tools for Java projects</a>.</p>

<hr />

<h3 id="2-development-tools-and-strategies">2. Development Tools and Strategies</h3>

<p>Now, let&#8217;s talk about the development tools. All that fancy code and great architecture will not bring you any closer to a developer&#8217;s paradise if there will not be some proper tools to support the development. The code should live in a proper version control system that supports collaboration and things like branching and tagging. There should also be tools that help you with code quality analysis, static code analysis, etc. A good starting point here would be to start with answering the following about the project in question:</p>

<ul>
  <li>Do you use a proper code versioning tool &#8211; Git, or even SVN?</li>
  <li>Do you have a branching (and tagging) strategy?</li>
  <li>Do you have a way of measuring code complexity?</li>
  <li>Do you have a way of measuring test coverage and results?</li>
  <li>Do you run static code analysis?</li>
</ul>

<p>Some tools that can help you here (again, for Java-based systems):</p>

<ul>
  <li><strong>IDEs and IDE plug-ins</strong> that can do checks at commits, integrate with test and QA tools, etc.</li>
  <li><strong>Build tools:</strong> Maven, Gradle, etc.</li>
  <li><strong>Continuous integration tools:</strong> Jenkins, TeamCity, Bamboo, etc.</li>
  <li><strong>Frameworks and tools for testing</strong>: to run unit tests, integration tests, UI tests, and end-to-end tests.</li>
</ul>

<p>There are some further strategies and questions to consider:</p>

<ul>
  <li>Are your environments easy to reproduce with minimal efforts &#8211; can you rebuild it by simply running a script?</li>
  <li>Do you have a proper pipeline from <em>packaging</em>, to <em>delivery</em>, to <em>deploy</em>?</li>
  <li>To what environments can you deploy automatically? With the same script, or command?</li>
  <li>Are your environments (like <em>development</em>, <em>testing</em>, <em>staging</em>, <em>pre-prod</em>, <em>production</em>) similar to each other?</li>
  <li>Do you follow the same process to deploy to each environment?</li>
  <li>Are <em>QA</em> and <em>production</em> running on physically separate hardware?</li>
  <li>Are you monitoring all of the environments? (i.e. are you able to see errors before they make it to <em>QA</em> or even <em>production</em>?)</li>
</ul>

<hr />

<h3 id="3-documentation-and-collaboration-tools">3. Documentation and Collaboration Tools</h3>

<p>Last, but not least, we will need to talk about the tools for collaboration and documentation. Without these tools, we will be back to the way things were several decades ago &#8211; with documents on shared network drives and other horrors of the 90&#8217;s that I mentioned at the beginning of this post. However, good wikis, other collaboration tools, and proper issue tracking will bring your software to another level, encouraging continuous improvement of the system.</p>

<ul>
  <li>Wiki</li>
  <li>Collaboration &#8211; chat, etc.</li>
  <li>Issue tracking tools</li>
</ul>

<p>No matter how obvious it might seem, it is still important to note that one should avoid multiple documentation and issue tracking systems. Unfortunately, even though it might sound obvious, it is more common than you think &#8211; I have seen my share of systems for documentation and issue tracking resulting in fragmented information and confusion.</p>

<h2 id="conclusion">Conclusion</h2>

<p>There are several challenges connected with having and maintaining the good code quality. The first challenge is that a good code quality is not something you can achieve overnight. It takes time and energy to achieve that and it is a continuous process. You will need some tools, techniques, and methodology to prevail, and it will probably be easier to introduce all that from the beginning of a project.</p>

<p>The second challenge would be that it might be hard to convince the stakeholders of the project to invest time and resources into something that does not bring any visible improvements to the table &#8211; things like new features and bug fixes are more likely to get prioritized over something that cannot be easily measured.</p>

<p>Actually, while presenting on this topic at JavaOne 2017 in San Francisco, several of the attendees asked me about the ways of getting to a beautiful nightmare-free code and infrastructure, and the ways of convincing the stakeholders that this is the way to go. Unfortunately, there is no one simple solution to this, and the most valuable thing, in this case, would be to show the real value of the good quality code.</p>

<p>The measurements parameters to show the value can be:</p>

<ul>
  <li>time it takes from the code is written to deploy,</li>
  <li>system stability,</li>
  <li>how often bugs are reported compared to earlier, or</li>
  <li>frequency of errors in logs.</li>
</ul>

<p>So, what can you do as a developer on a project that might need some help, you might ask? You can just start by continuously suggesting improvements and showing their value to the customer, or the project manager. Now you just need to keep going and gradually improving the system, one small bit at a time.</p>

<hr />]]></content><author><name>Rustam Mehmandarov</name></author><summary type="html">Common pitfalls in software development and practical suggestions on how to fix them.</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://mehmandarov.com/assets/images/posts-images/mindthegap.png"/><category term="blog"/><category term="java"/><category term="field notes"/><category term="software development"/><category term="english"/></entry><entry><title type="html">Command Line Tools for Your Java Projects</title><link href="https://mehmandarov.com/cmd-tools-for-developers/" rel="alternate" type="text/html" title="Command Line Tools for Your Java Projects"/><published>2017-05-15T20:46:00+02:00</published><updated>2017-05-15T20:46:00+02:00</updated><id>https://mehmandarov.com/cmd-tools-for-developers</id><content type="html" xml:base="https://mehmandarov.com/cmd-tools-for-developers/"><![CDATA[<p><em>Getting an overview of your project with some simple command line tools.</em></p>

<ul>
  <li><a href="#introduction">Introduction</a></li>
  <li><a href="#directory-structure">Directory Structure</a></li>
  <li><a href="#code-metrics">Code Metrics</a></li>
  <li><a href="#encoding-and-mime-types">Encoding and MIME types</a></li>
  <li><a href="#dependencies">Dependencies</a></li>
  <li><a href="#sonarqube">SonarQube</a></li>
</ul>

<hr />

<h2 id="introduction">Introduction</h2>
<p>This post will give you an overview of some command line tools that will be able to help you to get the feeling on how your project is doing. Most of the tools are widely available in the main Linux distributions and MacOS (some of them might need installation of <a href="https://brew.sh/" target="_blank">Homebrew</a> for Mac). On Windows it can be also made available via <a href="http://www.cygwin.com/" target="_blank">Cygwin</a>, or <a href="https://msdn.microsoft.com/en-us/commandline/wsl/about" target="_blank">Bash on Windows</a>.</p>

<p>The commands below have been run and tested on a MacOS machine, and might sometimes need some slight modifications to be run on a Linux or a Windows machine. However, it should be able to give an idea of what it is possible to do with these tools. I will also be linking to the documentation for each of the programs in the post.</p>

<hr />

<h2 id="directory-structure">Directory Structure</h2>
<p>Let&#8217;s start with something simple. Sometimes all you want to see is the contents and structure of the project without leaving the command line. The <code class="language-plaintext highlighter-rouge">tree</code> <a href="http://mama.indstate.edu/users/ice/tree/" target="_blank">command</a> might be able to help you out here.</p>

<p>It is highly customizable, takes lots of parameters, and is widely available for an installation via most of the package mangers. Command Prompt on Windows also contains a native alternative with the same name.</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>tree sourcecodefolder/ <span class="nt">-L</span> 1 <span class="nt">-d</span>
sourcecodefolder
&#9500;&#9472;&#9472; src
&#9500;&#9472;&#9472; tests
&#9500;&#9472;&#9472; sql
&#9492;&#9472;&#9472; docs</code></pre></figure>

<h2 id="code-metrics">Code Metrics</h2>
<p>If you want to see some metrics about the code in your project, like what languages that are used in the project, as well as information about number files, blank lines, comments, and lines of code, you might want to try the <code class="language-plaintext highlighter-rouge">cloc</code> <a href="https://github.com/AlDanial/cloc" target="_blank">command</a> (it stands for <em>Count Lines of Code</em>).</p>

<p>Simply install the program and point it at the project directory, or a zip file:</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>cloc sourcecodefolder/</code></pre></figure>

<p>It will give you a result that might look something like this:</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nt">-------------------------------------------------------------------------------</span>
Language                     files          blank        comment           code
<span class="nt">-------------------------------------------------------------------------------</span>
Java                            33           1226           1026           3017
Python                           4            327            337            888
Markdown                         1             11              0             28
SQL                             10             10             12            212
<span class="nt">-------------------------------------------------------------------------------</span>
SUM:                            48           1574           1375           4145
<span class="nt">-------------------------------------------------------------------------------</span></code></pre></figure>

<p>Also, it is possible to show all the information by percent:</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>cloc <span class="nt">--by-percent</span> cmb sourcecode.zip</code></pre></figure>

<h2 id="encoding-and-mime-types">Encoding and MIME types</h2>

<p>Files, within a single project, with different, or wrong, encoding might mean trouble with showing non-ASCII characters correctly. They might even give you compilation errors. Therefore, finding and marking those files as quickly as possible might help you manage your project.</p>

<p>While MIME types, on the other hand, are not as bad at causing trouble, the diversity of the MIME types among the same kind of files, like <code class="language-plaintext highlighter-rouge">*.java</code> files in this example, might indicate a lack of a standard for developer tools and code standard in the project.</p>

<p>This kind of information can be extracted with <code class="language-plaintext highlighter-rouge">file</code> command for each file, or it might be done a bit more automatic for the whole project, and it might look like this:</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>find <span class="nb">.</span> <span class="nt">-name</span> <span class="k">*</span>.java | <span class="se">\</span>
    xargs file <span class="nt">-I</span> <span class="nv">$1</span> | <span class="se">\ </span>
    gawk <span class="s1">'match($0, /.* (.*); charset=(.*)$/, gr) {print gr[2]}'</span> | <span class="se">\</span>
    <span class="nb">sort</span> | <span class="nb">uniq</span> <span class="nt">-c</span></code></pre></figure>

<p>A short explanation for the script:</p>

<ol>
  <li>find all java files recursively (<code class="language-plaintext highlighter-rouge">find</code> command)</li>
  <li>process them with the <code class="language-plaintext highlighter-rouge">file</code> command</li>
  <li>grab the output and extract data with regex (<code class="language-plaintext highlighter-rouge">gawk</code>)</li>
  <li>sort, extract unique values and count (<code class="language-plaintext highlighter-rouge">sort</code>, <code class="language-plaintext highlighter-rouge">uniq</code>)</li>
</ol>

<p>The result will look something like this:</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash"> 257 iso-8859-1
 117 unknown-8bit
 678 us-ascii</code></pre></figure>

<p>If you want to drill down a bit further and search for both MIME types and encoding, showing the distribution of encoding per MIME type, you can also extract that from the information supplied by the <code class="language-plaintext highlighter-rouge">file</code> command like this:</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>find <span class="nb">.</span> <span class="nt">-name</span> <span class="k">*</span>.java | <span class="se">\ </span>
    xargs file <span class="nt">-I</span> <span class="nv">$1</span> | <span class="se">\</span>
    gawk <span class="s1">'match($0, /.* (.*); charset=(.*)$/, gr) \
    {print gr[1] " --- " gr[2]}'</span> | <span class="se">\</span>
    <span class="nb">sort</span> | <span class="nb">uniq</span> <span class="nt">-c</span></code></pre></figure>

<p>A short explanation for the script is almost the same as above. The only difference is that we use information from both of the regex groups (<em>gr[1]</em>, and <em>gr[2]</em>). The result will look something like this:</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash">  15 text/html <span class="nt">---</span> iso-8859-1
  34 text/html <span class="nt">---</span> us-ascii
 134 text/plain <span class="nt">---</span> iso-8859-1
  16 text/plain <span class="nt">---</span> unknown-8bit
   1 text/plain <span class="nt">---</span> us-ascii
   1 text/x-c <span class="nt">---</span> iso-8859-1
   8 text/x-c <span class="nt">---</span> us-ascii
   5 text/x-c++ <span class="nt">---</span> iso-8859-1
   6 text/x-c++ <span class="nt">---</span> us-ascii</code></pre></figure>

<h2 id="dependencies">Dependencies</h2>
<p>Now, over to a bit more advanced stuff &#8211; analyzing dependencies in your project. Why would you want to do that? Well, in short: dependencies increase complexity, and cyclic dependencies are bad for your project and your health. They also hurt your modularity and complicate the build process.</p>

<p>This kind of analysis can be done with <a href="https://github.com/clarkware/jdepend" target="_blank">jdepend</a>. It is easy to run and can be run both separately, and as a part of a build tool, like <a href="http://www.mojohaus.org/jdepend-maven-plugin/" target="_blank">Maven</a>.</p>

<p>For some basic dependency analysis you can also use the command line, and do something like this:</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>find some_module/ <span class="nt">-name</span> <span class="k">*</span>.java | <span class="se">\</span>
    xargs <span class="nb">cat</span> <span class="nv">$1</span> | <span class="se">\</span>
    gawk <span class="s1">'match($0, /import (no.*);/, gr) {print gr[1]}'</span> | <span class="se">\</span>
    <span class="nb">sort</span> | <span class="nb">uniq</span>  | <span class="se">\</span>
    <span class="nb">grep</span> <span class="nt">-v</span> no.ignore.this.namespace <span class="c"># -v option add strings to ignore</span></code></pre></figure>

<p>A short explanation for the script:</p>

<ol>
  <li>find all java files recursively (<code class="language-plaintext highlighter-rouge">find</code> command)</li>
  <li>print them to console with the <code class="language-plaintext highlighter-rouge">cat</code> command</li>
  <li>grab the output and extract import statements with some specific pattern with regex (<code class="language-plaintext highlighter-rouge">gawk</code>)</li>
  <li>sort, extract unique values (<code class="language-plaintext highlighter-rouge">sort</code>, <code class="language-plaintext highlighter-rouge">uniq</code>)</li>
  <li>add some namespaces to ignore some strings (<code class="language-plaintext highlighter-rouge">grep</code> with a <code class="language-plaintext highlighter-rouge">-v</code> option)</li>
</ol>

<h2 id="sonarqube">SonarQube</h2>
<p>Last but not least, you might want to load your code for further analysis to <a href="https://www.sonarqube.org/" target="_blank">SonarQube</a>. This is an extremely powerful and free tool for doing the static analysis of your code. Normally, you would do that via a plug-in in your continuous integration (CI) software, like <a href="https://jenkins.io/" target="_blank">Jenkins</a>. However, there might be some cases when you might want to load this data manually, via a command-line.</p>

<p>To load the code to SonarQube you will first need to add a property file in the root directory of each module. It might look like this:</p>

<figure class="highlight"><pre><code class="language-text" data-lang="text"># Contents of sonar-project.properties file:
sonar.projectKey=my:SomeFancyProject
sonar.projectName=My SomeFancyProject
sonar.projectVersion=1.0
sonar.sources=.
sonar.sourceEncoding=ISO-8859-1</code></pre></figure>

<p>Then you will need to install and run <a href="https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner" target="_blank">SonarQube Scanner</a> from each module directory that contains <code class="language-plaintext highlighter-rouge">sonar-project.properties</code> file:</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash">sonar-scanner</code></pre></figure>

<p>As a <strong><em>bonus</em></strong> feature, I might also suggest that if you don&#8217;t have time setting up SonarQube on a separate machine, but want  to take a quick peek on how your project is doing, you can download and boot it up as a <a href="https://store.docker.com/images/sonarqube" target="_blank">Docker image</a> in no time, and later decide whether you want to create a dedicated machine for running SonarQube, or keep it as it is. Just remember that the database the SonarQube image uses out of the box should not be used for anything other than testing.</p>

<hr />]]></content><author><name>Rustam Mehmandarov</name></author><summary type="html">Getting an overview of your project with simple command-line tools.</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://mehmandarov.com/assets/images/posts-images/graph.jpg"/><category term="blog"/><category term="java"/><category term="software development"/><category term="english"/></entry><entry><title type="html">Five Pillars of a Good Maven Project</title><link href="https://mehmandarov.com/five-pillars-of-a-good-maven-project/" rel="alternate" type="text/html" title="Five Pillars of a Good Maven Project"/><published>2016-07-23T08:26:00+02:00</published><updated>2016-07-23T08:26:00+02:00</updated><id>https://mehmandarov.com/five-pillars-of-a-good-maven-project</id><content type="html" xml:base="https://mehmandarov.com/five-pillars-of-a-good-maven-project/"><![CDATA[<p><em>What makes a Maven project good to work with and easy to maintain? There are five types of Maven plugins that will simplify the development process and increase maintainability of a project.</em></p>

<ul>
  <li><a href="#1-technical-aspects">1. Technical Aspects</a></li>
  <li><a href="#2-legal-aspects">2. Legal Aspects</a></li>
  <li><a href="#3-rapid-development">3. Rapid Development</a></li>
  <li><a href="#4-documentation">4. Documentation</a></li>
  <li><a href="#5-testing-and-qa">5. Testing and QA</a></li>
  <li><a href="#bonus-video">Bonus: Video</a></li>
</ul>

<hr />

<p><a href="https://maven.apache.org/">Apache Maven</a> is a build automation tool used primarily for Java projects. It has been around for a while, and it does not seem to be going anywhere anytime soon (whether some of you like it or not). Recently, it has been confirmed yet again, this time in ZeroTurnaround&#8217;s <a href="http://zeroturnaround.com/rebellabs/java-tools-and-technologies-landscape-2016-trends/">Java Tools and Technologies Landscape Report 2016</a> (see the <em>Build Tools</em> section).</p>

<p>The good thing about Maven is that you can do almost anything with it and its plugins. With such a great ecosystem of plugins, able to do nearly anything, one might wonder where to begin when setting up a new Maven project or improving your old one.</p>

<p>I usually like to think of five main categories &#8211; or pillars &#8211; that we will be looking into in this post. Each category will have a set of example plugins that are meant to serve merely as a starting point.</p>

<p>In this post, I will assume that you have some experience with build tools in general and Maven in particular.</p>

<hr />

<h2 id="1-technical-aspects">1. Technical Aspects</h2>

<p>First of all, you would like to make sure that all the technical stuff is in place. You might want to automate the packaging, the checks if the project is running the latest version of all artifacts, that all the dependencies are met, and that the unused dependencies are removed. You might even want to define your own rules for all the things that cause troubles, or just simply annoy you down the line, making the build fail if they are not met.</p>

<p>With all that automation in place, you will be getting predictable results and nice packaging from the first day of the project.</p>

<p>Some of the plugins that should be mentioned here:</p>

<ul>
  <li><strong><a href="http://www.mojohaus.org/versions-maven-plugin/">Versions</a> plugin</strong> does the versions management of artifacts in a project&#8217;s POM file</li>
  <li><strong><a href="http://maven.apache.org/plugins/maven-dependency-plugin/">Dependency</a> plugin</strong> helps you analyzing dependencies, building dependency trees, showing unused dependencies, etc</li>
  <li><strong><a href="http://maven.apache.org/plugins/maven-assembly-plugin/">Assembly</a> plugin</strong> helps you packaging all the dependencies, modules, site documentation, and other files into a single distributable archive</li>
  <li><strong><a href="http://maven.apache.org/enforcer/maven-enforcer-plugin/">Enforcer</a> plugin</strong> lets you make your own rules! You can set up your build to break if some of your requirements are not met</li>
</ul>

<hr />

<h2 id="2-legal-aspects">2. Legal Aspects</h2>

<p>With all the technical stuff out of the way, we might want to make sure that the legal side is taken care of as well.</p>

<p>Yes, I know, it might be less fun thinking about licenses than writing code, but it is still something that has to be done. You still have to release your code under some kind of license, and you will have to make sure that the third-party licenses do not violate your own licensing. So, why not leave that job to a plugin?</p>

<p>The following plugin will manage the license of a maven project and its dependencies; it will also update file headers, download dependency licenses, check third-party licenses, etc.</p>

<ul>
  <li><strong><a href="http://www.mojohaus.org/license-maven-plugin/">License</a> plugin</strong></li>
</ul>

<hr />

<h2 id="3-rapid-development">3. Rapid Development</h2>

<p>Now, back to coding. Or even better &#8211; to seeing the results of your hard work. The chances are that you will need some kind of web or application server for running your code, and you want to able to deploy to that server in no time. Another kind of plugins that will be helping you from the very first day of the project.</p>

<p>Some of the plugins that can be mentioned here:</p>

<ul>
  <li><strong><a href="http://tomcat.apache.org/maven-plugin.html">Apache Tomcat</a> plugin</strong></li>
  <li><strong><a href="https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-maven-plugin">Jetty</a> plugin</strong></li>
  <li><strong><a href="https://docs.jboss.org/wildfly/plugins/maven/latest/">WildFly</a> plugin</strong></li>
  <li><em>&#8230;or any other deploy plugin, depending on your application</em></li>
</ul>

<hr />

<h2 id="4-documentation">4. Documentation</h2>

<p>Every decent project must also be properly documented. However, this is something that developers might postpone until the end. Well, no more! This kind of plugins will help you to get started early and will help you to produce some beautiful (<em>maybe?</em>) and maintainable docs.</p>

<p>You might even consider coupling these with some rules in the Enforcer plugin, but tread carefully as too many, and too strict rules can, and usually do, backfire.</p>

<ul>
  <li><strong><a href="https://maven.apache.org/plugins/maven-site-plugin/">Site</a> plugin</strong></li>
  <li><strong><a href="http://asciidoctor.org/docs/asciidoctor-maven-plugin/">Asciidoctor</a> plugin</strong></li>
</ul>

<hr />

<h2 id="5-testing-and-qa">5. Testing and QA</h2>

<p>By now, your code should be looking great, with all the right licenses, and up and running in no time. So, how about squashing some [virtual] bugs? The list below might help you setting up a proper QA environment and fixing bugs before the come crawling to your production servers.</p>

<ul>
  <li><strong><a href="http://maven.apache.org/surefire/maven-surefire-plugin/">Surefire</a> plugin</strong></li>
  <li><strong><a href="http://maven.apache.org/surefire/maven-failsafe-plugin/">Failsafe</a> plugin</strong></li>
  <li><strong><a href="http://www.mojohaus.org/sonar-maven-plugin/project-info.html">SonarQube</a> plugin</strong></li>
  <li><strong><a href="http://gleclaire.github.io/findbugs-maven-plugin/">FindBugs</a> plugin</strong></li>
  <li><strong><a href="https://maven.apache.org/plugins/maven-pmd-plugin/">PMD</a> plugin</strong></li>
</ul>

<hr />

<h2 id="bonus-video">Bonus: Video</h2>

<p>A video of a talk I gave about this topic at <a href="http://2015.javazone.no/details.html?talk=86734cc36c24b081d399454534248f3aad7062ce30de5aea27de84f80a476269">JavaZone</a> in Oslo (in Norwegian).</p>

<iframe src="https://player.vimeo.com/video/138955650?byline=0&amp;portrait=0" width="640" height="360" frameborder="0" webkitallowfullscreen="" mozallowfullscreen="" allowfullscreen=""></iframe>

<hr />]]></content><author><name>Rustam Mehmandarov</name></author><summary type="html">The five main types of Maven plugins that will simplify the development process and increase maintainability of a project.</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://mehmandarov.com/assets/images/posts-images/desk-pencils_1200x800.jpg"/><category term="blog"/><category term="field notes"/><category term="maven"/><category term="software development"/><category term="build and deploy"/><category term="automation"/><category term="java"/><category term="english"/></entry></feed>
