<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Guy MANDINA</title>
    <description>The latest articles on DEV Community by Guy MANDINA (@guyghost).</description>
    <link>https://dev.to/guyghost</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F285900%2F0cf29342-1ad8-4869-b646-44e4dde903e7.JPG</url>
      <title>DEV Community: Guy MANDINA</title>
      <link>https://dev.to/guyghost</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/guyghost"/>
    <language>en</language>
    <item>
      <title>Configure your Mac for Java Development</title>
      <dc:creator>Guy MANDINA</dc:creator>
      <pubDate>Sun, 15 Mar 2020 20:44:12 +0000</pubDate>
      <link>https://dev.to/guyghost/configure-your-mac-for-java-development-44b8</link>
      <guid>https://dev.to/guyghost/configure-your-mac-for-java-development-44b8</guid>
      <description>&lt;p&gt;About a year ago, I joined &lt;a href="https://hackages.io/"&gt;Hackages&lt;/a&gt; team to start working on a new training about &lt;strong&gt;"Migrating Java App from version 8 to 12"&lt;/strong&gt;. We had an exciting challenge on our hands: we needed to build content from scratch to help Java developers to move forward with new versions of Java.&lt;br&gt;
Indeed since 2017, Oracle &amp;amp; the Java community announced its shift to a new 6-month cadence for Java.&lt;br&gt;
Over time applications needs to be evolved to follow the evolution of the Java language. This resulted in a decision to upgrading our training.&lt;br&gt;
With these changes, we need to be able to switch between different versions of Java without a headache. Here's how to make it easier to manage multiple versions of Java on your Mac.&lt;/p&gt;
&lt;h2&gt;
  
  
  1. Install Homebrew
&lt;/h2&gt;

&lt;p&gt;Homebrew is free and open-source package management software for macOS that makes it easy to install programs. Installation is done in a command-line&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;/bin/bash &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; https://raw.githubusercontent.com/Homebrew/install/master/install.sh&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Install jEnv
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;JAVA_HOME&lt;/strong&gt; is an integral part of the workflow of a Java developer. We need it to build, compile, and launch our projects.&lt;br&gt;
&lt;a href="https://www.jenv.be/"&gt;jEnv&lt;/a&gt; is a command-line solution that allows us to manage the JAVA_HOME environment variable.&lt;/p&gt;

&lt;p&gt;The command to install jEnv via Homebrew is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;brew &lt;span class="nb"&gt;install &lt;/span&gt;jenv
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now that jEnv is installed, we can add the different versions of Java that we need.&lt;/p&gt;

&lt;p&gt;We can already list the versions listed with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;jenv versions
  system
  1.8
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Install the Java version you need
&lt;/h2&gt;

&lt;p&gt;Many things have changed since Java 8, not just in terms of features in the language. Oracle has started publishing two different versions, each with a different license (a commercial version that you must pay to use in production and an open-source OpenJDK version) and has modified its update and support templates. This new policy created some confusion in the community, but in the end, it gave us more choice over the JDK we use. We must consider both the options available to us and what we expect from the JDK.&lt;/p&gt;

&lt;p&gt;To install a new version of Java, we use Homebrew again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;brew cask &lt;span class="nb"&gt;install &lt;/span&gt;adoptopenjdk13
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The last thing to do is now to add this new version to Jenv.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can verify if the version correctly added.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;jenv versions
 &lt;span class="k"&gt;*&lt;/span&gt;system
  1.8
  13.0.1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can now change the version fo your choice.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;jenv global 13.0.1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Open a command prompt and check java version to make sure you have change for the new version of Java.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;java &lt;span class="nt"&gt;-version&lt;/span&gt;
openjdk version &lt;span class="s2"&gt;"13.0.1"&lt;/span&gt; 2019-10-15
OpenJDK Runtime Environment AdoptOpenJDK &lt;span class="o"&gt;(&lt;/span&gt;build 13.0.1+9&lt;span class="o"&gt;)&lt;/span&gt;
OpenJDK 64-Bit Server VM AdoptOpenJDK &lt;span class="o"&gt;(&lt;/span&gt;build 13.0.1+9, mixed mode, sharing&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And voilà 😎. Now we can switch versions as we want. &lt;/p&gt;

&lt;h2&gt;
  
  
  One more thing (Advice for the upgrade)
&lt;/h2&gt;

&lt;p&gt;Each upgrade process will be specific to the migrated application. However, some good basic practices make the process easier. These described in the order in which you should address them, and you will see that for the first few steps, you do not even need to use an updated JDK.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do not ignore the compiler warnings
&lt;/h3&gt;

&lt;p&gt;Warnings are there for a reason, and if you read them, they often talk about features that may disappear in the future. If you are working with Java 8, on a JDK 8, and you see obsolescence warnings or feature warnings that you should not use, correct these warnings before attempting to switch to a JDK more recent.&lt;/p&gt;

&lt;p&gt;Note that deprecation is taken much more seriously in recent versions of Java and that Java 10 and Java 11 have removed APIs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Update your build tool
&lt;/h3&gt;

&lt;p&gt;If you use &lt;strong&gt;Maven&lt;/strong&gt; or &lt;strong&gt;Gradle&lt;/strong&gt;, you must upgrade.&lt;/p&gt;

&lt;h4&gt;
  
  
  Gradle
&lt;/h4&gt;

&lt;p&gt;Gradle 6.0 introduced Java 13 support, so we should use at least Gradle in version 5.0 to use Java version beyond 9. The current release version is 6.2.2.&lt;/p&gt;

&lt;h4&gt;
  
  
  Maven
&lt;/h4&gt;

&lt;p&gt;We must use at least version 3.5.0 (the current version is 3.6.3), and we must make sure that the Maven compiler plugin is at least version 3.8:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;plugin&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.apache.maven.plugins&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;maven-compiler-plugin&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;3.8.1&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;configuration&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;release&amp;gt;&lt;/span&gt;11&lt;span class="nt"&gt;&amp;lt;/release&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!-- or 12 or 13 --&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;/configuration&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/plugin&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Update your dependencies
&lt;/h3&gt;

&lt;p&gt;Some of the problems you may have heard about migrating to Java 9 or later are problems encountered (and potentially corrected) by libraries and frameworks. For example, many frameworks use reflection and underlying internal APIs. For your application to have the best chance of continuing to work correctly, you must make sure that all your dependencies are up to date. Many libraries have already been updated to work with Java 9 and beyond, and there is an ongoing effort by the community to ensure that this continues.&lt;/p&gt;

&lt;h3&gt;
  
  
  Start using new features
&lt;/h3&gt;

&lt;p&gt;Only when everything works, all your tests will run, and everything looks good, and maybe after some time in production, you can consider using the new language features.&lt;br&gt;
Also, remember that even though Java version 9 has introduced the module system in Java, applications do not need to use it at all, even if they have migrated to a version that supports it.&lt;/p&gt;

</description>
      <category>java</category>
      <category>macos</category>
      <category>jenv</category>
      <category>homebrew</category>
    </item>
  </channel>
</rss>
