Maven Jspc plugin not working with java 8 - java-8

We are using maven-jspc-plugin with java 8 and it’s giving class compilation errors though we are giving source and target as 1.6 java version.
So it’s not working with 1.8 or 1.6 java versions.
Unknown target VM 1.6 ignored.
Compilation error
org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException
Arrays cannot be resolved
The type java.util.Comparator cannot be resolved. It is indirectly referenced from required .class files
<plugin>
<groupId>org.apache.sling</groupId>
<artifactId>maven-jspc-plugin</artifactId>
<executions>
<execution>
<id>compile-jsp</id>
<goals>
<goal>jspc</goal>
</goals>
<configuration>
<jasperClassDebugInfo>false</jasperClassDebugInfo>
<compilerSourceVM>1.6</compilerSourceVM>
<compilerTargetVM>1.6</compilerTargetVM>
</configuration>
</execution>
</executions>
</plugin>

Related

How can I compile a project that implements interfaces in generated sources folder from openapi generator?

I am using the OpenAPI generator maven plugin with kotlin-spring generator to generate interfaces for my API based on the specification.
As an example, I used the specification by this blog post and the following plugin configuration:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.1.0</version>
<executions>
<execution>*
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>
${project.basedir}/src/main/resources/petstore.yml
</inputSpec>
<generatorName>kotlin-spring</generatorName>
<modelNameSuffix>Dto</modelNameSuffix>
<configOptions>
<basePackage>com.example</basePackage>
<apiPackage>com.example.api</apiPackage>
<modelPackage>com.example.model</modelPackage>
<configPackage>com.example.config</configPackage>
<delegatePattern>true</delegatePattern>
<interfaceOnly>true</interfaceOnly>
<supportingFilesToGenerate>
ApiUtil.kt
</supportingFilesToGenerate>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
When I run mvn clean generate-sources then the files are properly generated in target/generated-sources/openapi/....
I then create an implementation of the delegate in my src folder where I can override the methods of the generated interface:
package com.example.api
class PetsApiDelegateImpl : PetsApiDelegate {
}
Up to now, everything is good and IntelliJ is also happy with it. However, when I run mvn clean compile the target folder is deleted and re-generated again as expected but I still receive an error:
[ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.5.31:compile (compile) on project choreographer: Compilation failure
[ERROR] /path/to/example/src/main/kotlin/com/example/api/PetsApiDelegateImpl.kt:[3,29] Unresolved reference: PetsApiDelegate
In other words, the files are generated as part of mvn clean compile but compilation still fails because the interface is not found.
How can I successfully compile this project?
We can resolve the compilation failure by adding an execution for the compile goal to the kotlin-maven-plugin that configures the generated directory as source directory.
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.build.directory}/generated-sources/kotlin/src/main/kotlin</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>

Check Java Version/API compat in maven without installing old JDKs?

Is there a way to make sure that maven modules are API-compatible to older Java releases without installing and using the specific JDK release? Ie. some plugin?
Example: java.lang.String.isBlank() is available from JDK 11 only, so the plugin should check whether that method has been used if target version is <=10.
Alternatively, I could write a few plugin executions to download/unpack a jdk and then build the current project against that specific jdk. However, that'd be ugly.
the animal sniffer recommendation works great:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.17</version>
<executions>
<execution>
<id>verify-java-api</id>
<goals>
<goal>check</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java18</artifactId>
<version>1.0</version>
</signature>
</configuration>
</plugin>
Update: that animal sniffer configuration did not find this issue:
symbol: variable RELEASE_10
location: class javax.lang.model.SourceVersion

${session.executionRootDirectory} is not recognized by sonar-maven-plugin

I have several levels of nested Maven projects, where every module can participate in the global integration tests. To have a global, multi module coverage, I've configured jacoco to use and share the same file accross modules, using the Maven variable ${session.executionRootDirectory}:
<execution>
<id>pre-integration-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<propertyName>jacoco.failsafeArgLine</propertyName>
<destFile>${session.executionRootDirectory}/target/jacoco-it.exec</destFile>
</configuration>
</execution>
This way, the same data file is used by each module, no matter how deep it is nested in the submodules. I've checked, a correct data file is generated by jacoco when launching "mvn clean install".
Now the problem appears when launching mvn sonar:sonar. It seems that the plugin can not replace that variable with the real path. I can see the following in the logs
[INFO] JaCoCoItSensor: JaCoCo IT report not found: /home/tomcat/.jenkins/jobs/MYJOB/workspace/${session.executionRootDirectory}/target/jacoco-it.exec
It doesn't work better when using #{session.executionRootDirectory}.
Any workaround?
Following a comment in this bug report at SonarSource, advising to use the following configuration:
<plugin>
<groupId>com.github.goldin</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>0.2.5</version>
<executions>
<execution>
<id>set-sonar.jacoco.reportPath</id>
<goals>
<goal>set-properties</goal>
</goals>
<phase>initialize</phase>
<configuration>
<rawProperties>
sonar.jacoco.itReportPath = ${session.executionRootDirectory}/target/jacoco-it.exec
</rawProperties>
<addDollar>true</addDollar>
</configuration>
</execution>
</executions>
</plugin>
... which was unfortunately not compatible with Maven 3.1+, I've used and built from sources that fork, and then I was able to make everything work correctly with Maven 3.2.3.

Unable to build Maven project due to Javadoc error?

Has anyone come across a similar Maven error as below?
I am unable to build my project due to the error below. All was working previously fine before I started working on the code.
I did not even work on the below defined interfaces and it seems to be related to Javadoc?
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:2.9.1:jar (attach-javadocs) on project jonney-project: MavenReportException: Error while creating archive:
[ERROR] Exit code: 1 - /Users/me/Work/myProject/library/src/main/java/com/me/someInterface.java:45: warning: no #return
[ERROR] public abstract boolean searchForDevce();
[ERROR] ^
[ERROR] /Users/me/Work/myProject/src/main/java/com/me/someInterfaceAgain.java:52: warning: no #return
[ERROR] public abstract boolean selectDevice(int pos);
[ERROR] ^
I'm guessing you switched to Java 8. In this version Javadoc is stricter on the requirements.
You have three choices:
Fix the errors
disable the strict checking
skip Javadoc when building
To disable the strict checking, add this to your pom.xml
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</plugin>
</plugins>
to skip Javadoc while building, use this:
mvn -Dmaven.javadoc.skip=true verify
Further Information
With maven-javadoc-plugin version 3.0.0 <additionalparam/> has been replaced by <additionalOptions/>. To reduce the errors to warnings this pom.xml entry worked for me:
<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>
<configuration>
<additionalOptions>
<additionalOption>-Xdoclint:none</additionalOption>
</additionalOptions>
</configuration>
</plugin>
</plugins>
</build>
UPDATE FOR THOSE WHO GOOGLED THIS BUG:
If the project uses source/target 8, adding 8 in javadoc configuration should make the project buildable on jdk {11, 12, 13}:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<source>8</source>
</configuration>
...
Just update your pom.xml with the properties tag, given below.
<properties>
<additionalparam>-Xdoclint:none</additionalparam>
</properties>
None of the above options seemed to work for me when using version 3.2.0. Instead I noticed the failOnError option. Setting this tags value to false seemed to do the trick for allowing my build to succeed even when there were javadoc errors.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven.javadoc.plugin.version}</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<failOnError>false</failOnError>
</configuration>
</plugin>
This will stop the javadoc jar from being generated for the maven project. This was okay in my case as I was only wanting to build without errors during ongoing development. The other options may still allow for the javadoc jar to be generated when there are errors.
As mentioned by #turbanoff since version 3.0.0 the maven-javadoc-plugin config setting <additionalparam> has been replaced by <additionalOptions>
So the plugin defintion in your pom.xml can look like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<additionalOptions>-Xdoclint:none</additionalOptions>
</configuration>
</plugin>
This configuration will still generate the warnings. So you can and should fix them in your code. But it will now no longer break the maven build.

How to download JDK installer by maven?

I try to download Oracle (Sun) Java JDK via maven without success:
<dependency>
<groupId>com.sun</groupId>
<artifactId>jdk</artifactId>
<version>6u45</version>
<classifier>dlj-linux-i586</classifier>
<type>bin</type>
</dependency>
What maven repository should I use to download Oracle (Sun) Java JDK?
Added
I want to find a way to download DLJ version of jdk-6u45-linux-i586.bin JDK installer by maven, without manually download.
Now i have standard maven error when dependency is not configured well or a maven repository is missed:
Missing:
----------
com.sun:jdk:bin:dlj-linux-amd64:6u45
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=com.sun -DartifactId=jdk -Dversion=6u45 -Dclassifier=dlj-linux-amd64 -Dpackaging=bin -Dfile=/path/to/file
How to download JDK installer by maven?
You can't. The JDK installer is not in any public Maven repository. If it was, the Oracle lawyers would be sending "cease and desist" letters.
I am aware that you could use the Maven exec plugin (or similar) to "work around" Oracle's click through license agreement. However, this is arguably illegal under US law. Consider what happened to "weev" when prosecutors decided to make an example of him.
When you're running on a linux machine, you can download the jdk using maven-exec-plugin calling curl/wget :
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<!-- using curl -->
<execution>
<id>download oracle jdk (curl)</id>
<phase>process-resources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>curl</executable>
<arguments>
<argument>-L</argument>
<argument>--header</argument>
<argument>Cookie: s_nr=1359635827494; s_cc=true; gpw_e24=blub; s_sq=[[]]; gpv_p24=novalue</argument>
<argument>http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-i586.bin</argument>
<argumen>-o</argumen>
<argument>${project.build.directory}/curl-jdk-6u45-linux-i586.bin</argument>
</arguments>
</configuration>
</execution>
<execution>
<!-- using wget -->
<id>download oracle jdk (wget)</id>
<phase>process-resources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>wget</executable>
<arguments>
<argument>--no-cookies</argument>
<argument>--header</argument>
<argument>Cookie: s_nr=1359635827494; s_cc=true; gpw_e24=blub; s_sq=[[]]; gpv_p24=no value</argument>
<argument>http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-x64.bin</argument>
<argument>-O</argument>
<argument>${project.build.directory}/wget-jdk-6u45-linux-x64.bin</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
...
I have developed maven plugin which can download and unpack OpenJDK from different providers (Liberica, Adopt, SapMachine), it is useful for preparing cross-platform JDK images in distributives
<plugin>
<groupId>com.igormaznitsa</groupId>
<artifactId>mvn-jlink-wrapper</artifactId>
<version>1.0.2</version>
<executions>
<execution>
<id>cache-jdk-8</id>
<goals>
<goal>cache-jdk</goal>
</goals>
<configuration>
<jdkPathProperty>jlink.jdk.path</jdkPathProperty>
<jdkCachePath>${project.build.directory}${file.separator}jdkCache</jdkCachePath>
<provider>ADOPT</provider>
<providerConfig>
<release>jdk8u192-b12</release>
<arch>x64</arch>
<type>jdk</type>
<impl>hotspot</impl>
</providerConfig>
</configuration>
</execution>
</executions>

Resources