Java Version for PMD, Findbugs and Checkstyle - java

I need to use PMD, Findbugs and Checkstyle in Eclipse for a Development project. Is Java 6 enough to use these tools? or I need java 7?

Java 6 is enough (Even 5 will work).

Everything should work for
1.5>=Java<1.8
Findbugs
FindBugs requires JRE (or JDK) 1.5.0 or later to run. However, it can
analyze programs compiled for any version of Java, from 1.0 to 1.7.
Some classfiles compiled for Java 1.8 give FindBugs problems, the next
major release of FindBugs will handle Java 1.8 classfiles.
http://findbugs.sourceforge.net/
Checkstyle
Added Java 7 support to the grammar. Thanks to Dinesh Bolkensteyn for
patch #3403265
http://checkstyle.sourceforge.net/releasenotes.html
PMD
•2011-11-04 PMD 4.3 (download): ◦Add support for Java 7 grammer -
thanks to Dinesh Bolkensteyn and SonarSource
http://pmd.sourceforge.net/pmd-4.3/

Notice latest PMD requires Java 7/8
running PMD only requires Java 7 (or Java 8 for Apex and the Designer).

Related

Should I update aspectJ when migrating from java 6 to 8?

My AspectJ version is still on 1.6.8 running on a Java 6 Project.
Suppose I migrate to Java 8.
Should I update the AspectJ version? Is it mandatory?
If yes, are there things I have to be aware of?
This question was flagged as a duplicate before, but I voted to re-open it because the other question was about AspectJ Maven Plugin compatibility with Java 8 and the answers there do not explain anything explicitly in order to answer this question.
AspectJ 1.6.x was published for Java 6, just as AspectJ 1.7.x was for Java 7, 1.8.x for Java 8, 1.9.x for Java 9-13 at the date of writing this.
Having said that, you should consider the following:
If you would just use the Java 8 compiler but compile your Java 6 code with target 1.6, in theory you could continue using AspectJ 1.6.8 (e.g. runtime) too.
But as soon as you compile with target 1.8 and/or use Java 8 language features, you have to use AspectJ 1.8.x (I recommend the latest version) at least in order to make the AspectJ compiler and weaver understand those language features and the byte code at all.
I would even recommend to use the latest 1.9.x version, it is backward compatible and might have a few bug fixes missing in 1.8.x. But that is an optional choice. I always use the latest AspectJ version even in Java 8.

JMockit and Jacoco Java 5

I see in version JMockit 1.8 support for Jacoco was fixed, however this also went hand in hand with making Java 6 a minimum requirement.
Is there a way of getting version 1.8 to work with a build runtime of Java 5? Or even patching the fix for Jacoco into version 1.7? What changed, could I do it?
We can't upgrade our build servers for a few months, so this would really help us use this feature.
You can use Java 6 as compiler, and make a war 1.5 compliant. Anyway, the tests are not deployed on server side.... (Or I hope so)

Drools rule compilation error on upgrade to Java 7

I'm using Drools (5.5.0) rules in my Java project (managed using maven 2.2.1). It works fine in Java 6 (1.6.0_45), but when I move to Java 7 (1.7.0_51) and build, certain rules give a rule compilation error such as the following:
Rule Compilation error : [Rule name='SampleRuleName']
com/sample/event/rules/simple/Rule_SampleRuleName46467274.java (2:486) : Syntax error, static imports are only available if source level is 5.0
com/sample/event/rules/simple/Rule_SampleRuleName46467274.java (2:500) : The import com.sample.event.rules.simple.TransformEvent.transformEvent cannot be resolved
com/sample/event/rules/simple/Rule_SampleRuleName46467274.java (7:1082) : The method transformEvent(TransformedEventCallBackHandler, EventTemplate, FirmwareEvent) is undefined for the type Rule_SampleRuleName46467274
The "static imports are only available if source level is 5.0" error suggests the drools compiler is setting a source level less than 5, but why would it do that? I've update my JAVA_HOME and my pom.xml. It should be picking up the Java source level from there, right?
Upgrade to Drools 6, this issue is fixed there. We had a similar issue for Java 8 recently with Drools 6.0 and it's fixed for 6.1 (and recent versions of 6.0 too).
The cause for java 8 was that drools recognizes java versions 1.6, 1.7, but not 1.8 at which point it defaults to 1.6. I suspect that drools 5.5 (which is old) had the same problem for java 7.
Turns out Drools uses the Eclipse JDT compiler to compile rules. Upgrading the JDT version did the trick. However if that fails, upgrading the Drools version might also help.

AspectJ works with Java 7?

I instaled AspectJ in Eclipse (AJDT), but the specific methods of Java 7 are marked as errors when I use the AspectJ project.
My doubt is if AspectJ works with Java 7 or this is an issue with Eclipse or AJDT.
EDIT: The problem is AJDT that doesn't support AspectJ for Java 7 yet. There is some IDE to AspectJ that supports?
You need AspectJ 1.7.0 M1 (or higher) for Java 7 compatibility. http://www.eclipse.org/aspectj/doc/released/README-170.html
From the aspectJ webpage:
"AspectJ 1.7.0.M1 is now available for download. See the readme for more information. This is our first Java7 compiler based milestone." so it should work. Did you search at all?
You should install the snapshot version of the AspectJ Development Tools (AJDT) from this update site:
http://download.eclipse.org/tools/ajdt/37/dev/update

JDK compiler version issue

I'm using Ant to compile Java.The project has to be compiled using JDK 1.5 , however some part of the code references a package compiled with JDK 1.6 version.
I set the JAVA_HOME to 1.5 , error is thrown at this reference as
[javac] class file has wrong version 50.0, should be 49.0
What is the way out without downgrading the reference version to 1.5
What you are asking isn't possible. You should compile your library with JDK 1.5.
Once Java has been compiled at a certain version, you cannot use that version on older versions of Java.
The package you are using might have a version available which is suitable for an older version of Java, alternatively you may be able to get the source code and recompile with the older version (if it doesn't use any Java 6 libraries / features).
Think this way:
The library you use has been compiled using JDK 6. It may be using some features introduced in Java 6 (that were not part of previous versions of Java)
When you use JDK 5 to compile and run, what do you expect the compiler (and the runtime) to do when this "new" feature is encountered? The JDK 5 does not know this feature and will be "confused"
To avoid this confusion at runtime, the compile itself fails.
You have two options:
Compile your project using JDK 6.
Get a JDK 5 compiled version of your library
If your project were using JDK 6 and the library was compiled with JDK 5, then you wouldn't have faced this issue because of backwards compatibility.

Categories

Resources