version mismatch of maven-compiler-plugin - maven

I have this lines under our pom.xml file
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<jdkLevel>1.6</jdkLevel>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
I am using apache-maven-2.2.1 version .
Will it be any problem as the versions of maven-compiler-plugin and maven Version does not match ??
Please suggest , thank you very much .

The versions of maven and its plugins never match. There is no coordination of the releases. It is very rare for there to be compatibility issues and when they exist they are documented on the plugin documentation pages.

Related

Cannot create jar files for Maven project

I Have very complex Maven project with multiple Feature file , for below POM.XML , I cannot create jar file
MAven Install Package is failing as below:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:testCompile
If I change jre version to 1.7 , am getting error for dimond symbol <>
Could someone help to build Jar file ?
POM.XML :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<fork>true</fork>
<executable>C:\Program Files\Java\jre1.8.0_161\bin\javac</executable>
</configuration>
</plugin>
I think your maven compiler section is using an out of date plug in. You're using 3.3, the latest is version 3.7.0 so I'd update to that.
For example my pom.xml contains:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
I'm also running the latest version of Maven on my development box too, which I think is 3.5.3 but I could be very much mistaken on that front.
Maven Central is a great place to look stuff like this up. The link for the compiler plugins is provided below:
https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin
Hope that helps.

when to use <build> plugin in maven pom.xml?

In our project, we have configured jetty inside build plugin in pom, i want to understand configuration settings in pom/ what and all we can configure in pom.
what is <build><plugin> section in pom, when to use.
difficult to understand from tutorials because lot of different examples which is making confuse.
Please can somebody explain for the above in detail?
Plugins defined in your buildsection plugins tag will be executed during the build of your project.
There are many plugins that do something with your build.
For example the maven-compiler-plugin which allows you to set the Java version for your project.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
a list of maven build plugins supported by maven itself

Maven where is it looking for the JDK?

4th time typing this message up as this crappy machine I am to use crashes randomly throughout the day. Gotta love it.
My development environment JAVA_HOME is set to "c:jdk1.7.0_45"
and in the POM I have the following
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable>${JAVA_HOME}\jdk1.7.0_45\bin\javac</executable>
<compilerVersion>1.7</compilerVersion>
<configuration>
</plugin>
but have also tried
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
So Why do I get the error: multi-catch statement is not supported in -source 1.5?
I don't see anything that references 1.5.
Also, I am not clear on what the source and target are exactly am only assuming things, same for what maven-compiler-plugin is to stand for.
Any straight forward answers to these questions would be greatly appreciated as I'm new and not aware to go read up on the section I don't know about because what I'm working on I don't know what it's called nor what I am to be asking what I am to be looking up. Nobody in house has a clue either as to how to use Maven. Appreciate any guidance in this painful environment.
===========================
The following is how I had to have it in order for the default of 1.5 not to execute.
Changed the JAVA_HOME to the JDK 1.7 path.
<configuration>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<source>1.7</source>
<target>1.7</target>
</configuration>
However, other projects that require the 1.6 are now broken. What a horrible setup.
For maven compiler plugin, as explained here
the default source setting is 1.5 and the default target setting is
1.5
Also as mentioned in the link you can try the configuration "forceJavacCompilerUse"
try using
<properties>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.test.skip>true</maven.test.skip>
</properties>

two plugins difference in maven's pom

Maybe at the beginning that question is stupid and i get minuses but..
please tell me which one plugin code should i use ?
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
or
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<!-- put your configurations here -->
</configuration>
</plugin>
</plugins>
The groupId is optional since org.apache.maven.plugins is the default
groupID, yet I would recommend keeping it around anyway
You should always use the version tag to pin down the plugin
version and avoid surprises regarding regressions introduced in newer
plugins.
If you are sure about the JDK you develop for, you should definitely
specify the source and target version
So use a combination of the above IMHO
You should use the second one, especially if you use maven 3.
It is a good practice to explicitly specify the groupId so that there is no confusion. Some plugins are available from org.codehaus.mojo, for instance. Maven does resolve the plugin as documented here.
version is relevant if you are using maven3, as described here.
You would still specify the source/target versions in either case, if you want it to be different from the jdk you are using.

Maven Install: "Annotations are not supported in -source 1.3"

When running mvn install on my project, i see it fail due to the following errors:
C:\Repositories\blah\src\test\java\com\xxx\qm\testrunner\test\ATest.java:[11,5] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
#Test
C:\Repositories\blah\src\test\java\com\xxx\qm\common\test\BTest.java:[11,5] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
#Test
My Maven dependency includes jUnit 4.8, however and has no reference to 1.3 anything.
What would cause these errors? Please advise
You need to specify the source version of your maven project through the use of the maven-compiler-plugin. Add the following to your pom build element and set the appropriate java source and target levels.
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
http://maven.apache.org/plugins/maven-compiler-plugin/
A shorter version:
<project>
<properties>
<maven.compiler.source>1.5</maven.compiler.source>
<maven.compiler.target>1.5</maven.compiler.target>
</properties>
....
You are most likely using OpenJDK where the source level is 1.3 when not explicitly set - as opposed to Oracle JDK where the source level is 1.5.
Since most modern Java projects target newer code than Java 5 you most likely need to set this anyway.
Also note that if you need a lower target than source (e.g. for compiling with Java 6 but deploying to Java 5) you can do this by using the Eclipse compiler instead of Javac.
Bu default, the maven tries to compile using Java 1.3 version. I hope most of them hit this error because of missing to tell maven that "Hey Maven, Dont use 1.3 and use "whatever_version_I_give"
This can be mentioned in pom.xml as below :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
In my above example, I have used 1.7. Please replace with whatever version you wish to.
Add this in your pom
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<!-- put your configurations here -->
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

Resources