Maven where is it looking for the JDK? - maven

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>

Related

Module 'xxx' is imported from Maven. Any changes made in its configuration may be lost after reimporting

⭐I have met the following problem several times, and dealt with it over and over...
⭐Until today, I found out where the problem is, but can't solve it~
Module 'xxx' is imported from Maven. Any changes made in its configuration may be lost after reimporting
⭐As the picture shows, once I reimport All Maven projects, its version will change to 13 from 8...
⭐After reimporting, it comes back:
I would appreciate it very grateful if you can assist me..
add the following codes in the pom.xml of your project:
<build>
<plugins>
<!-- ensure jdk 1.8-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
configure both <source> and <target> to 1.8(it's up to you).
reason: you have never set the jdk version. so every time you modify the pom.xml and reimport the dependencies, it will revert to the default JDK 13.

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.

Installing and compiling Maven artifacts on Java 8

I have a project with a pom.xml that has the following <build> declaration:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
When I run mvn install on this project, it compiles the project, runs unit tests and publishes it to my local repo. I am trying to learn a little more about Maven here, and am having a tough time finding documentation/explanations on the following:
How am I able to run mvn install, if the POM doesn't declare it under build/plugins? Does maven-compiler-plugin include maven-install-plugin, if so, how could I have figured that out?
Most importantly: the value of build/plugins/plugin/configuration/source and .../target are both set to 1.8. If my machine has Java 8 on it, and I run mvn install on this project without any errors, does that guarantee that the project builds with Java 8? I'm looking at the docs for the Compiler Plugin and don't see those source/target configs listed anywhere.
First you should learn what the build life cycle is and how it works and how the plugins are bound to the life cycle by default.
Furthermore you should understand that in Maven every project inherits from the super pom file which is part of the maven distribution (the package you have downloaded). The super pom defines the default folder layout and some versions of plugins.
The question to define the maven-compiler-plugin as you did is to be very accurate simply wrong. You should have defined it like the following:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
This would overwrite the definition which is inherited by the super pom and changes it's configuration. In your case i would suggest to change the definition into this:
<project>
...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
..
</project>
The encoding should be set globally cause there are other plugins which use this definition like the maven-resources-plugin. The usage of the above property simplifies this, cause every plugin which has an option for encoding will use the default as defined in the property.
To be sure using the correct version of Java (your JDK on your machine) you have to use the maven-enforcer-plugin.
Apart from that please take a look onto the plugins page which shows the most up-to-date releases of the plugins.
As a good documentation i can recomment the Books on Maven but be aware they are written with Maven 2 in mind. So if something is not clear ask on users mailing list of here on SO.

version mismatch of maven-compiler-plugin

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.

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.

Resources