How to make apt-maven-plugin work with java 8 - java

I am migrating from java 6 to java 8. I have a maven project and it has apt-maven-plugin which is not running on jdk 1.8. Do we have a workaround or an alternate to make it work with java 8? Is it possible to run apt-maven-plugin with java 8??
Please find below the maven entry:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.0-alpha-3</version>
<configuration>
<factory>
com.emc.tsg.common.xml.ABCGenerator
</factory>
<includes>
<include>**/model/*.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
</plugin>
and i have changed the maven tools.jar dependency for java 8 as:
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.8</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
I have changed the java version as:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<optimize>true</optimize>
<debug>false</debug>
</configuration>
</plugin>
When i am trying to run mvn compile, i am getting apt compiler not found error. I think in jdk tools.jar there is no apt class unlike java 6 hence wondering if at all its possible to achieve this in java 8?

Related

Maven JavaDoc listed classes twice

I am using the javadoc maven plugin and it creates the correct javadoc package, but all classes are created twice.
Maven dependency:
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.0</version>
</dependency>
My build code
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Can anyone help me please, what am I missing here?
command usage for doc generation
mvn clean install -Dresources="FirstProject/example_API"
I noticed the same problem and came upon a solution after enabling debug on the maven-javadoc-plugin maven plugin and seeing what it's doing. Specifically setting the sourcepath as shown below fixed the double listing problem for me and I've tried this on multiple version of Corretto 8 as well as Temurin 8. All had the double listing problem because it's an issue with the javadoc tool itself but setting the sourcepath manually fixed it for me.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<debug>true</debug>
<sourcepath>${basedir}/src/main/java</sourcepath>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
There's a bug in recent versions of the Maven Javadoc Plugin. The bug is known as MJAVADOC-700. It is dead easy to reproduce.
Downgrading to version 3.2.0 of the plugin fixes the problem. Setting the sourcepath explicitly is an alternative fix.

Is there a way to use an older version of Java with scala-maven-plugin

I would need to compile a legacy scala project (Scala version 2.8.0). The version is incompatible with JDK8. So I would like to ideally compile the project using JDK 7. I am looking for a configuration something like the following in maven-compiler-plugin.
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
Is there a similar configuration in scala-maven-plugin?
I have tried using "source" as suggested in the documentation of the plugin and javacargs as well. But both those options don't work.
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.4.2</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<recompileMode>incremental</recompileMode>
<source>1.7</source>
<target>1.7</target>
<javacArgs>
<javacArg>-source</javacArg>
<javacArg>1.7</javacArg>
<javacArg>-target</javacArg>
<javacArg>1.7</javacArg>
</javacArgs>
</configuration>
</plugin>
Does anyone know what I am doing wrong? I don't have the option of using JDK7

Upgrading to Java 11, sonarqube, jacoco with maven causing errors

After upgrading Java from 8 to 11. sonar:sonar is not working getting exception
in the end.
Java 1.8 is working fine with Sonarqube 7.7, now with java 11 and sonarqube 7.8 it is failing with exception
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.6.0.1398:sonar (default-cli) on project xxxx: Unable to read ....\target\jacoco.exec to determine JaCoCo binary format.: EOFException -> [Help 1]
Using below properties for java 11
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
<sonar.sources>src/main</sonar.sources>
<sonar.tests>src/test</sonar.tests>
<runSuite>**/*Test.class</runSuite>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis
<sonar.jacoco.reportPaths>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPaths>
<sonar.language>java</sonar.language>
Below plugins using jacoco
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>${java.version}</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<argLine>--illegal-access=permit</argLine>
<includes>
<include>${runSuite}</include>
</includes>
<forkCount>0</forkCount>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<configuration>
<destFile>${sonar.jacoco.reportPaths}</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<id>agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
Am I missing any configuration in pom file to run sonarqube using jacoco
Removing sonar.coverage.jacoco.xmlReportPaths and maven-surefire-plugin gave the code coverage. Issue is fixed.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<argLine>--illegal-access=permit</argLine>
<includes>
<include>${runSuite}</include>
</includes>
<forkCount>0</forkCount>
</configuration>
</plugin>
Useful links:
https://52.213.100.93/browse/MMF-1651
https://github.com/SonarSource/sonar-scanning-examples/tree/master/sonarqube-scanner-maven
The issue was with property need to include sonar.coverage.jacoco.xmlReportPaths
<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/../target/jacoco.exec</sonar.coverage.jacoco.xmlReportPaths>
After changing the mvn sonar:sonar is successful but the code coverage is 0%

maven with JDK11: javac: invalid flag: --release

I'm trying to set up a simple maven project with java 11. As I want to keep JAVA_HOME to be version 8, I'm using maven-toolchains-plugin to make maven use jdk11 for this project.
While maven successfully finds a matching toolchain for jdk-11.0.1, I keep getting " javac: invalid flag: --release". What am I doing wrong?
Here are the plugin configurations:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
<configuration>
<toolchains>
<jdk>
<version>11</version>
</jdk>
</toolchains>
</configuration>
</plugin>
The toolchain is defined as:
<toolchain>
<type>jdk</type>
<provides>
<version>11</version>
<id>JavaSE-1.11</id>
</provides>
<configuration>
<jdkHome>C:\Program Files\Java\jdk-11.0.1\bin</jdkHome>
</configuration>
<toolchain>
As I found out, the configuration is just fine. The problem was that jdkHome in toolchains.xml was pointing to the \jdk-11.0.1\bin direction instead of \jdk-11.0.1 directly..... Using <jdkHome>C:\Program Files\Java\jdk-11.0.1</jdkHome> solves the problem..
Changing the jdk version should fix the problem mostly. Replace
<version>1.11</version>
with
<version>11</version>
Do ensure though that your maven is configured with JDK-11 using the command mvn -version and confirming the Java version there. You can also verify the toolchains.xml JDK configured as well.
In case you're trying to compile using different versions of the compiler, you need to ensure executions under the maven-compiler-plugin as:
<executions>
<execution>
<id>java11</id>
<phase>none</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<release>11</release>
<jdkToolchain>
<version>11</version>
</jdkToolchain>
<compileSourceRoots>
<compileSourceRoot>${project.basedir}/src/main/java11</compileSourceRoot>
</compileSourceRoots>
<outputDirectory>${project.build.outputDirectory}/META-INF/versions/11</outputDirectory>
</configuration>
</execution>
</executions>
Here is the sample pom.xml referred for the above.

How to configure Maven to build two versions of an artifact, each one for a different target JRE

I have a maven module that I need to use in the J2ME client and in the EJB server. In the client I need to compile it for target 1.1 and in the server for target 1.6 .
I also need to deploy the 1.6 version to a Nexus repository, so the members working on the server project can include this dependency without needing to download the source code.
I've read at http://java.dzone.com/articles/maven-profile-best-practices that using profiles is not the best way of doing this, but the author didn't say what's the best way.
Here is my pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>proj-parent</artifactId>
<groupId>br.com.comp.proj</groupId>
<version>0.0.4-SNAPSHOT</version>
</parent>
<artifactId>proj-cryptolib</artifactId>
<name>proj - Cryto Lib</name>
<dependencies>
<dependency>
<groupId>br.com.comp</groupId>
<artifactId>comp-proj-mobile-messages</artifactId>
<version>0.0.2-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.3</source>
<target>1.1</target>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
</project>
As Haylem suggests thought you'll need to do it in two steps, one for the compile and one for the jars.
For the compiler
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<configuration>
<source>1.3</source>
<target>1.5</target>
<fork>true</fork>
<outputDirectory>${project.build.outputDirectory}_jdk5</outputDirectory>
</configuration>
</execution>
<execution>
<configuration>
<source>1.3</source>
<target>1.6</target>
<fork>true</fork>
<outputDirectory>${project.build.outputDirectory}_jdk6</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
And then for the jar plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>${project.build.outputDirectory}_jdk5</classesDirectory>
<classifier>jdk5</classifier>
</configuration>
</execution>
<execution>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>${project.build.outputDirectory}_jdk6</classesDirectory>
<classifier>jdk6</classifier>
</configuration>
</execution>
</executions>
</plugin>
you can then refer to the required jar by adding a <classifier> element to your dependency. e.g.
<dependency>
<groupId>br.com.comp.proj</groupId>
<artifactId>proj-cryptolib</artifactId>
<version>0.0.4-SNAPSHOT</version>
<classifier>jdk5</classifier>
</dependency>
You can configure this via the Maven compiler plugin.
Take a look at the Maven compiler plugin documentation.
You could enable this via different profiles for instance.
If you only want to have different target versions you could simply use a variable target. Something like this:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.3</source>
<target>${TARGET_VERSION}</target>
<fork>true</fork>
</configuration>
</plugin>
To complement my comment to wjans' answer, as you requested more details.
The following would have the compiler plugin executed twice to produce two different sets of classfiles, identified by what is called a classifier (basically, a marker for Maven to know what you refer to when a single project can produce multiple artifacts).
Roughly, something like:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<configuration>
<source>1.3</source>
<target>1.5</target>
<fork>true</fork>
<classifier>jdk5</classifier>
</configuration>
</execution>
<execution>
<configuration>
<source>1.3</source>
<target>1.6</target>
<fork>true</fork>
<classifier>jdk6</classifier>
</configuration>
</execution>
</executions>
</plugin>
Note that people sometimes frown on using classifiers, as they on using profiles, as they can possibly mean that your project should be scinded in multiple projects or that you are harming your build's portability.

Categories

Resources