How to run PMD for java 1.6 in Maven - java

I am trying to configure PMD into a legacy application that needs to run in java 1.6 (this is mandatory). I am trying to find a version of pmd-plugin that was build at least again java 1.6. If I use maven-pmd-plugin it complains not being binary compatible with jre 1.6.
The problem is older version of PMD net.sourceforge.pmd seems to be ignored and maven-pmd-plugin:3.8 always run instead no matter the version I use.
Now I am trying with no lucky with this.
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>5.0.0</version>
</dependency>

The latest PMD release to be compiled against Java 6 was PMD 5.4.6. (last of the 5.4.x branch). Ever since 5.5.0 PMD has required Java 7.
You can tell the Maven plugin to use whichever version of PMD you require by setting it's dependencies explicitly.
You can see the docs on how to do so here

Related

Is it possible to build a maven project on one java version and run it on another java versions?

I am new to maven projects. I am curious to know that is it possible to build my maven project on JAVA version 1.8 and run it on JAVA version 11. In simple word, can I compile or build a maven project on JDK 1.8 and run it on JRE 11?
Yes. Newer JDKs can run older bytecode, so if you compile for Java 8, you can, usually, run it on Java 11. Sometimes changes in the Java API or support for the newer Java runtime in your dependencies may necessitate changes in your code though.
Conversely, you can also use Maven to configure the compiler to output Java 8 bytecode while using a Java 11 JDK yourself in the <plugins> section of your Maven build:
<plugin>
<!-- Configure the compiler. -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<!-- Note that this 'release' parameter was introduced in JDK 9. -->
<release>8</release>
</configuration>
</plugin>
What you cannot do though, is compile Java 11 bytecode using JDK 8. If you want to generate Java 11 bytecode and use newer Java features introduced after Java 8, just install a JDK 11 release on your development machine.
As noted by meaningqo in the comments above, you are generally better of developing and building on the same major Java version as your target environment unless you need to target multiple (major) Java versions. Java is backwards compatible, but there are always quirks that can trip you up, and if you have any dependencies in your project you may find that these do not always work in a newer Java version even if they run fine on Java 8, or that you need a newer version of that dependency for Java 11 that won't work with Java 8.

Is there a way to get a map of maven plugin version and their required java version?

I'm maintaining a parent pom for my team which will provide the latest compatible version of various maven plugins per the JDK that the project uses. Sometimes if a project utilizes an older version of Java (like 1.5) maven will fail due to a plugin requiring a newer version. Is there a way to get a map of a given plugin and see what the minimum java version is for said plugin? I was thinking there was some sort of report or something that would show me that, but I'm not seeing anything.
What about: https://builds.apache.org/view/M-R/view/Maven/job/dist-tool-plugin/site/dist-tool-prerequisites.html Apart from that on every plugin page you can find the goals page which contains the information you need. One more thing if you are using not the most uptodate versions all older versions pages are available where you can look at which version which JDK versions uses. It shouldn't be problem to write some kind of script to programmatically extract the information of the older plugins. The above site contains the informations of the uptodate plugins.
Apart from that plugin version selection basead on JDK version is not a good idea. The plugins have only a minimum version for JDK they need to run with. Apart from that they run on all versions (already on JDK 9 with one exception)...Furthermore plugins might require a minimum Maven version to run with which is either Maven 2.2.1 or Maven 3.0+ which shouldn't a problem.
You should define your plugins versions simply based on problems you might have but i would recommend to keep uptodate with your plugins.
If you need running you build with JDK 6 for example, but you use Maven 3.3.X which needs JDK 7 to run you can achieve this by using toolchain to handle this situation.
In theory this shouldn't be an issue. Maven will use the Java version you run it with, so the plugin's dependency will be satisfied, independent of the project's language level. Just make sure your devs are using a current version.
Example: running Maven with Java 8 will satisfy the dependency of a Plugin that requires Java 8, independent of the project's source and target level.
(With dependencies it's more complicated, I am afraid, but since you are not actually coding against your plugins, you should be fine)

Installing Groovy 1.8 on Spring Tool Suite 3.6.1

I have Spring Tool Suite 3.6.1, which is based on Eclipse 4.4.
I installed the version of Grails I need, but I noticed that the Groovy compiler is at 2.3, whereas I need it to be at 1.8.
I've gone to dist.springsource.org on the Eclipse Marketplace to look for the Compiler 1.8. I can install it, but it automatically uninstalls the existing Grails IDE. On top of that, it doesn't appear under Preferences - Groovy - Compiler and I don't seem to be able to select it.
What am I doing wrong? Do I need to use an earlier version of the Spring Tool Suite to access this particular compiler?
I'd recommend using the snapshot update site to get the latest groovy-eclipse: http://dist.springsource.org/snapshot/GRECLIPSE/e4.4/
That includes the 1.8 compiler and the latest groovy-eclipse 2.9.1 builds that work with it - the 2.9.0 release had trouble with groovy 1.8. (But 1.8 is getting quite old now so we may drop support in the not too distant future).
That snapshot build should also be compatible with grails-ide, not sure why it would be uninstalling grails-ide (but remember that grails-ide is different to the grails-runtime - have you definitely installed both from the dashboard extensions page or just the runtime?)

Maven: Groovy-Eclipse Compiler plugin with Groovy 2.3.5

Since GMaven has been discontinued, I have been using Groovy-Eclipse Compiler plugin on my Maven projects. The version I used is 2.8.0-01 and I specifically used Groovy 2.1. I know 2.9.0-01-SNAPSHOT has been out for the longest time, but there's no ETA when it will be officially released.
My question here is... can I use safely use version 2.8.0-01 with Groovy 2.3.5 without potential side effects?
Thanks.
Since there is no groovy-eclipse-batch 2.3.5 you can not use it with any version of groovy-eclipse-compiler.
Probably there won't be a 2.3.5 of groovy-eclipse-batch ever, since groovy 2.3.6 has already been released. Once the 2.3.6 compiler is ported to greclipse, we will put out a release of the groovy-eclipse-batch artefact to maven central that is compatible with groovy-eclipsec-compiler 2.9.0 (which has recently been released)
Right now, the latest groovy-eclipse-batch you can use is 2.3.4-01 and it is compatible with the released version of groovy-eclipse-compiler 2.9.0-01.
For the latest released artefacts see:
http://search.maven.org/#search|ga|1|groovy-eclipse-batch
http://search.maven.org/#search|ga|1|groovy-eclipse-compiler
I don't think you can. Groovy-Eclipse adopts new versions of Groovy. In fact Groovy-Eclipe includes support for various versions of Groovy it supports. For each supported version of Groovy there will be a corresponding feature available from the update site. Groovy-Eclipse 2.9.0 has suppoort for Groovy 2.3.x and you'd have more luck with Groovy 2.3.5 with that version of Groovy-Eclipse.
There is some sort of a problem with Groovy 2.3.5 release, hence I'd recommend 2.3.6, which should be out now. Groovy-Eclipse support for Groovy 2.3.6 should be in very soon, hence I'd recommend to install Groovy-Eclipse from this update site at the end of the week: http://dist.springsource.org/snapshot/GRECLIPSE/e4.4
I was in the same situation as you with GMaven, switched to the Groovy-Eclipse, but note that there is a replacement for GMaven now, GMavenPlus, which works very much like the original GMaven, and I've switched back.
I was using 2.1, but wanted to upgrade to 2.3 because there were inconsistencies where groovyc would compile code using #CompileStatic while Groovy-Eclipse would give an error. The Groovy-Eclipse compiler had the advantage that it can compile Java and Groovy without stubs. The main advantage with GMavenPlus is that it compiles with the standard Groovy compiler of any version you want and also supports indy.
If Groovy-Eclipse is more important, the existing answers are all right. If using the version of Groovy you want and frequent upgrades is more important, then consider GMavenPlus.

Errormessage caused by Maven plugin manager - what is the reason?

I get a obscure error meesage, if i want to build my maven project with command "maven clean install":
Internal error in the plugin manager executing goal 'com.samaxes.maven:minify-maven-plugin:1.7:minify': Unable to find the mojo 'minify' (or one of its required components) in the plugin 'com.samaxes.maven:minify-maven-plugin'
com/samaxes/maven/minify/plugin/MinifyMojo : Unsupported major.minor version 51.0**
Was anybody an idea, how i can solve this problem?
//EDIT
It is possible to solve this problem without changing the current JDK 6 to JDK 7 ?
//EDIT again
Ok i could build my maven project. I have done the follwoing step but i´m not sure, if this was a good way of solution:
<plugin>
<groupId>com.samaxes.maven</groupId>
<artifactId>minify-maven-plugin</artifactId>
<version>1.6</version>
</plugin>
I have changed the version from 1.7 to 1.6 and now i can build the maven project. But is that really the best solution?
The plugin is compiled for Java 1.7 and you don't have a JDK7 installed (at least Maven is not running with that JDK)
This plugin was compiled for Java 7 and your system has previous Java version. Hence the problem with running MinifyMojo
As others have mentioned, this plugin is compile for Java 7. You can either upgrade your version of Java or you can check if any of the previous versions of your plugin were compiled with Java 6, or at least were compiled with Java 6 compatibility turned on.

Categories