Thursday, May 19, 2011

how to fix "javac: invalid target release: 1.6" error

For reasons not worth going into, we are still running our project code under Java 1.5, and this has caused no end of interesting scenarios, including today's issue when attempting to run a unit test in debug mode. I received the following error in Compile Messages in IntelliJ (v9, also an involved story):
Information:Usage: javac  
Information:where possible options include:
Information: -g Generate all debugging info
Information: -g:none Generate no debugging info
Information: -g:{lines,vars,source} Generate only some debugging info
Information: -verbose Output messages about what the compiler is doing
Information: -deprecation Output source locations where deprecated APIs are used
Information: -classpath Specify where to find user class files
Information: -cp Specify where to find user class files
Information: -sourcepath Specify where to find input source files
Information: -bootclasspath Override location of bootstrap class files
Information: -extdirs Override location of installed extensions
Information: -endorseddirs Override location of endorsed standards path
Information: -d Specify where to place generated class files
Information: -encoding Specify character encoding used by source files
Information: -source Provide source compatibility with specified release
Information: -target Generate class files for specific VM version
Information: -version Version information
Information: -help Print a synopsis of standard options
Information: -X Print a synopsis of nonstandard options
Information: -J Pass directly to the runtime system
Information:Compilation completed with 1 error and 0 warnings
Information:1 error
Information:0 warnings
Error:javac: invalid target release: 1.6

I googled the last line of this and got a bunch of recommendations regarding pointing JAVA_HOME at Java 1.6, but because of our constraint that solution is not for us. Also, there was no mismatch between the Java version being used by IntelliJ and that being used by Maven (you can do mvn -version to check).

Finally I discovered that IntelliJ has a hidden little default setting in the compiler that was effing it up. I discovered it via the Maven tab -> properties, but it's just a project setting. I used the top left search field to search for Java. That gives several results, including one for the Java Compiler:

As you can see, there's this secret little config that is the cause of the problem:

Additional command line parameters: -target 1.6

DERP!

When I removed this parameter and reran my debug unit test, everything worked just fine.

HTH,
kewpiedoll99

2 comments:

doyleyboy said...

Thank you! Had this exact error. Bloody Maven

su said...

same here, thanks!