<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog4Java &#187; Compile</title>
	<atom:link href="http://malsolo.com/blog4java/?feed=rss2&#038;tag=compile" rel="self" type="application/rss+xml" />
	<link>http://malsolo.com/blog4java</link>
	<description>A personal and Java blog, likely only for me</description>
	<lastBuildDate>Tue, 31 Mar 2015 15:52:42 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.1.1</generator>
	<item>
		<title>Try to avoid copy-paste. Fatal error compiling: invalid target release: 1.8.0_11</title>
		<link>http://malsolo.com/blog4java/?p=297</link>
		<comments>http://malsolo.com/blog4java/?p=297#comments</comments>
		<pubDate>Tue, 12 Aug 2014 11:35:15 +0000</pubDate>
		<dc:creator><![CDATA[Javier (@jbbarquero)]]></dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Compile]]></category>
		<category><![CDATA[Error]]></category>
		<category><![CDATA[Plugin]]></category>

		<guid isPermaLink="false">http://malsolo.com/blog4java/?p=297</guid>
		<description><![CDATA[Bazinga! Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project&#8230;: Fatal error compiling: invalid target release: 1.8.0_11 -&#62; [Help 1] To summarize, I want to compile a maven project using Java 8, that is possible thanks to the JAVA_HOME configuration: [crayon-69e01e2701a5d540750825/] &#8230; <a href="http://malsolo.com/blog4java/?p=297">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><strong>Bazinga!</strong></p>
<p><font color=red>Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project&#8230;: <strong>Fatal error compiling: invalid target release: 1.8.0_11</strong> -&gt; [Help 1]</font></p>
<p>To summarize, I want to compile a maven project using Java 8, that is possible thanks to the JAVA_HOME configuration:</p><pre class="crayon-plain-tag">$ mvn -version
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T18:37:52+01:00)
Maven home: /home/jbeneito/Applications/apache-maven-3.2.1
Java version: 1.8.0_11, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-32-generic", arch: "amd64", family: "unix"</pre><p></p>
<p>But I copied the maven compiler plugin configuration from another maven project without putting special attention:</p><pre class="crayon-plain-tag">&lt;plugin&gt;
                &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                &lt;version&gt;3.1&lt;/version&gt;
                &lt;configuration&gt;
                    &lt;source&gt;${java.version}&lt;/source&gt;
                    &lt;target&gt;${java.version}&lt;/target&gt;
                    &lt;encoding&gt;${project.build.sourceEncoding}&lt;/encoding&gt;
                &lt;/configuration&gt;
            &lt;/plugin&gt;</pre><p>In programming the error usually contains the solution. I&#8217;m trying to use the current Java version (1.8.0_11) as the option for the javac command, that is not the expected one.</p>
<p><strong><em>${java.version}</em></strong> is a environment variable whose value is currently <strong><em>1.8.0_11</em></strong>, but the <a href="http://maven.apache.org/plugins/maven-compiler-plugin/index.html" title="Maven compiler plugin" target="_blank">Maven Compiler Plugin</a> expects the standard options of the <a href="http://docs.oracle.com/javase/8/docs/technotes/tools/windows/javac.html" title="javac" target="_blank">javac command</a> for <a href="http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html" title="Setting the -source and -target of the Java Compiler" target="_blank">Setting the -source and -target of the Java Compiler</a>.</p>
<p>That is:</p>
<ul>
<li><strong>1.3</strong> for Java SE 1.3</li>
<li><strong>1.4</strong> for Java SE 1.4</li>
<li><strong>1.5</strong> for Java SE 5</li>
<li><strong>5</strong> synonym for 1.5</li>
<li><strong>1.6</strong> for Java SE 6</li>
<li><strong>6</strong> synonym for 1.6</li>
<li><strong>1.7</strong> the default value. The compiler accepts code with features introduced in Java SE 7. (Yes, as it appears in the <a href="http://docs.oracle.com/javase/8/docs/technotes/tools/windows/javac.html" title="javac 8" target="_blank">Java 8 official documentation</a>)</li>
<li><strong>7</strong> Synonym for 1.7</li>
</ul>
<p>Actually I only use the values with the format 1.X, that includes 1.8, that I assume is the default value for Java 8 SE.</p>
<p>Why did I use this variable?</p>
<p>Because in my previous project it wasn&#8217;t an environment variable, but a custom property in the pom.xml:</p>
<p></p><pre class="crayon-plain-tag">&lt;properties&gt;
        &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
        &lt;java.version&gt;1.8&lt;/java.version&gt;
...
    &lt;/properties&gt;</pre><p></p>
<p>But this time I have another two custom properties:</p><pre class="crayon-plain-tag">&lt;properties&gt;
        &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
        &lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
        &lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;</pre><p></p>
<p>Thus the solution is easy:</p>
<ol>
<li>Try to not copy-paste</li>
<li>Pay attention in any case</li>
<li>Just use the appropriate variables</li>
</ol>
<p></p><pre class="crayon-plain-tag">&lt;plugin&gt;
                &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                &lt;version&gt;3.1&lt;/version&gt;
                &lt;configuration&gt;
                    &lt;source&gt;${maven.compiler.target}&lt;/source&gt;
                    &lt;target&gt;${maven.compiler.source}&lt;/target&gt;
                    &lt;encoding&gt;${project.build.sourceEncoding}&lt;/encoding&gt;
                &lt;/configuration&gt;
            &lt;/plugin&gt;</pre><p></p>
]]></content:encoded>
			<wfw:commentRss>http://malsolo.com/blog4java/?feed=rss2&#038;p=297</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
