How to compile java project against JDK 5? [duplicate] - maven-2

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
compiling project with jdk1.5 using maven2
I am trying to build java project that is using java 5 features, so maven is understandably returning an error message:
... variable-arity methods are not supported in -source 1.3
(use -source 5 or higher to enable variable-arity methods) ...
Could somebody help me understand:
- Why maven is not compiling against only installed jdk that is 6?
- How can I configure it to compile against a different jdk ie, 5 or 6?
- Do I need to install maven enforcer plugin whose only beta is available to date?
Thanks in advance

I really wish Maven would not default to Java 1.3 compiler settings.
Here is what I put in all my POM files:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<target>1.5</target>
<source>1.5</source>
</configuration>
</plugin>
</plugins>
</build>
Please anyone tell me that there is a better way.

Related

Maven Kotlin plugin with JDK 17 not working

Upgraded Kotlin from 1.5 to 1.8 today: build fails in JDK 17 due to:
java.lang.reflect.InaccessibleObjectException: Unable to make field protected java.io.OutputStream java.io.FilterOutputStream.out accessible: module java.base does not "opens java.io" to unnamed module #2ba9f986
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
at com.intellij.util.io.IOUtil.syncStream(IOUtil.java:217)
tried to add the following to my Maven configuration:
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<configuration>
<jvmTarget>${java.version}</jvmTarget>
<args>
<arg>"--add-opens java.base/java.io=ALL-UNNAMED"</arg>
</args>
</configuration>
</plugin>
but the problem is still there.
Official documentation does not seem to provide any info on this. Online search did not find much, apart from something about Gradle
Is there any Maven-plugin configuration to fix it? (ie build Kotlin 1.8 on JDK 17) or is that not supported?
For our Kotlin project build with Maven, We have the following file .mvn/jvm.config in the project folder. The content should be as follows:
--add-opens=java.base/java.lang=ALL-UNNAMED
--add-opens=java.base/java.io=ALL-UNNAMED

Tell IntelliJIdea to use specific JDK version, not just JDK8, but jdk-8u201

After a switch to JDK8 the MANIFEST.MF Attributes started returning null
https://bugs.openjdk.java.net/browse/JDK-8201636 suggests that this is a bug introduced by Oracle in JDK 8u151-8u172.
I use pom.xml and IntelliJ IDEA. pom.xml specifies (tags < and > removed)
<maven.compiler.target> 1.8 </maven.compiler.target>
<maven.compiler.source> 1.8 </maven.compiler.source>
IDEA settings show target bytecode version 1.8
JAVA_HOME set to JDK10
I have C:\Program Files\Java\jdk1.8.0_201 installed.
How to specify this version for the builds. Also does pom.xml trump IDEA project settings or vice versa?
Edit:
I've specified
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<!--executable>{JAVA_1_8_HOME}/bin/javac</executable-->
<executable>C:/Program Files/Java/jdk1.8.0_201/bin/javac</executable>
<compilerVersion>1.8</compilerVersion>
</configuration>
</plugin>
Intellij still defaults to JDK 1.5 and chokes on List<String> a = new ArrayList<>(); with "I don't understand <> with JDK1.5".
maven.compiler.target and source are nothing to do with it. Those are just arguments passed to javac.
If you want to specify the version of javac explicitly, you can use the Maven Compiler Plugin.
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable><!-- path-to-javac --></executable>
<compilerVersion>1.3</compilerVersion>
</configuration>
Otherwise the javac from the Project SDK will be used (Project Structure > Project).

Intellij ignoring Project java source level

Note: this is not a duplicate. This version of spark requires either jdk 1.7 or 1.8. The parent pom.xml entry is shown here:
<java.version>1.7</java.version>
As shown in the screenshot we have java 1.8 for the SDK and the language level:
And here are the modules settings:
But Intellij is just confused about that:
Error:(73, 51) java: diamond operator is not supported in -source 1.5
(use -source 7 or higher to enable diamond operator)
This is a spark project being built from maven on OS/X. Intellij Ultimate 14.1.4
Update Here is the pom.xml entry for the jdk
If you are using Maven, please watch your pom.xml file. Even if your IntelliJ Project is set to Java 8 your project will compile with the version of Java set in your pom.xml.
Add this to your pom.xml
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
Or directly in the maven plugin :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.2</version>
<configuration>
<source>1.8</source> <!-- java version here -->
<target>1.8</target> <!-- java version here -->
</configuration>
</plugin>

Intellij Idea 14.1.1problems evaluating lambda expressions

I am running evaluate expression for lambda expressions in my IDE,Intellij Idea 14.1.1.It gives me the message Unable to compile for target level 1.8. Need to run IDEA on java version at least 1.8, currently running on 1.6.0_65-b14-466.1-11M4716
The code compiles just fine and runs fine too,only when i do evaluate expression while debugging do i get this problem.
I have checked all the compiler setting they are all set to 1.8.
Any ideas what setting i need to change?
Install java 8;
From Project Structure -> Project Settings ->
Project: select java 1.8 as Project SDK; select 8 - Lamdas, type
annotations etc.
From Settings -> Language & Frameworks ->
JavaScript -> Libraries: from the libraries list, make sure
ECMAScript 6 is selected.
Open pom.xml and enter Java configuration inside build:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

How to use javadoc:aggregate properly in multi-module maven project?

This is my parent pom.xml file (part of it) in a multi-module project:
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</build>
...
This plugin is inherited in all sub-modules and I don't think it's a correct approach. When I'm running mvn javadoc:aggregate the documentation is generated in target/site/apidoc, but the log is full of warnings:
...
[WARNING] Removing: aggregate from forked lifecycle,
to prevent recursive invocation.
...
What am I doing wrong?
You need to enable aggregation for this plugin:
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<aggregate>true</aggregate> <!-- this enables aggretation -->
</configuration>
</plugin>
On the commandline type:
mvn javadoc:aggregate
Edit:
Okay, I did some digging into maven plugin's jira and found that all the javadoc plugin mojos have been annotated with #aggregator. But there seem to be problems with maven's aggregator the issue for which has been filed here
There are also related bugs here and here and some more
This seems to be a blocker issue with maven's aggregator since some plugins like e.g. clover wont run.
To to summarize, you are doing nothing wrong
Just switch back to earlier versions of maven-javadoc-plugin that does not use #aggregator mojo annotation and you will not get the warnings (unless you are using certain feature of the javadoc plugin thats not available in earlier version)
On a side note, If you run the javadoc plugin as report then the #aggregator is ignored.