How to resolve maven EnforcedBytecodeVersion failure? - java

When trying to run maven enforcer getting a failure due to some classes conforming to 1.9 where as the entire project is confine dto 1.8. Following is the stack trace of the log. That specific dependency is being pulled by a different jar which can't be excluded as it has compile time dependency.
[INFO] Checking unresolved references to org.codehaus.mojo.signature:java18:1.0
[INFO] Restricted to JDK 1.8 yet javax.json.bind:javax.json.bind-api:jar:1.0:compile contains module-info.class targeted to JDK 1.9
[WARNING] Rule 14: org.apache.maven.plugins.enforcer.EnforceBytecodeVersion failed with message:
Found Banned Dependency: javax.json.bind:javax.json.bind-api:jar:1.0

It seemed to be that you misunderstand the intention of enforceBytecodeversion...It will check all dependencies if they use byte code for a more recent version as stated which means higher than JDK 8 just lifting the maxJdkVersion is not solving the problem. The problem is related to the dependencies you are using ....
The dependency: javax.json.bin:javax.json.bind-api
contains a `module-info.class` file which is related to JDK 9 ...
If you are sure all code in that dependency does not use JDK 9 specific things you have to exclude module-info.class from checking in enforcer rules...
Update:
This can be achieved by using the following:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>enforce-bytecode-version</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<enforceBytecodeVersion>
<maxJdkVersion>1.8</maxJdkVersion>
<ignoreClasses>
<ignoreClass>module-info</ignoreClass>
</ignoreClasses>
</enforceBytecodeVersion>
</rules>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>extra-enforcer-rules</artifactId>
<version>1.0-beta-9</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
[...]
</project>

By overriding the target bytecode to 1.9 in the child pom was able to resolve the enforcer issue as follows.
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<enforceBytecodeVersion>
<maxJdkVersion>1.9</maxJdkVersion>
</enforceBytecodeVersion>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>

Related

log4j not getting excluded from maven build

I am looking to exclude the log4j in my pom file. It is not even available in the remote repository.
I have a property with version 4.0.0 in the parent pom file.
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.3.0</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
<configuration>
<excludes>
<exclude>**/log4j*</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
It simply does not work; I keep getting the message below.
Execution scala-compile-first of goal net.alchim31.maven:scala-maven-plugin:4.3.0:add-source failed: Plugin net.alchim31.maven:scala-maven-plugin:4.3.0 or one of its dependencies could not be resolved: Failure to find org.apache.logging.log4j:log4j-core:jar:2.11.2
excludes configuration section inside the scala-maven-plugin is meant for filtering resources to be compiled.
In your case log4j is a dependency (already compiled), you have to find what is pulling it in the build and exclude it from there (or setup a global dependency exclusion rule).

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.

Upgrading past ANTLR 4.5 no longer processes grammar in maven

I have 4 ANTLR parser/lexers (they are separate, so 8 total), and they were written in version 4.2. Recently, I have updated to the newest 4.9.2 release, but I noticed during a mvn clean install it no longer processes the grammars. I went ahead and removed my generated .java parsers/lexers thinking it would acknowledge they were missing and regenerate them, but it did not and ended up failing the build due to test errors since they were missing.
It looks like this (issue?) starts after version 4.5, once I upgrade past there it no longer processes my grammars during a mvn clean install. Is there an additional parameter I need to specify this? Below is my antlr4 plugin in my pom.xml:
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.5</version>
<executions>
<execution>
<phase>generate-sources</phase>
<configuration>
<sourceDirectory>${project.basedir}/src/main/java/ast</sourceDirectory>
<outputDirectory>${project.basedir}/src/main/java/ast</outputDirectory>
<timestamp>false</timestamp>
<listener>false</listener>
<visitor>true</visitor>
</configuration>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
</plugin>
Edit: When running a version past 4.5, there is no error, it just simply states the following:
--- antlr4-maven-plugin:4.7:antlr4 (default) # projectname ---
No grammars to process
ANTLR 4: Processing source directory C:\Users...directory...\src\main\java\ast
This works for me:
<project ... >
...
<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.9.2</version>
<configuration>
<arguments>
<argument>-visitor</argument>
</arguments>
</configuration>
<executions>
<execution>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
With folder structure:
src/
main/
antlr4/
yourpackage/
YourGrammar.g4
the generated Java classes for the *.g4 grammars will be generated in: ./target/generated-sources/antlr4/yourpackage

Maven javadoc plugin build fails. How to add add portlet-api dependency

I have a vaadin project and I tried to configure javadoc plugin in my project. I added following plugin to build->plugins section of my pom.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</execution>
</executions>
</plugin>
....
</plugins>
</build>
When I run a mvn install, build fails with following error.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:2.10.4:jar (default) on project web-yaan-ui-base: MavenReportException: Error while generating Javadoc:
[ERROR] Exit code: 1 - javadoc: error - com.sun.tools.doclets.internal.toolkit.util.DocletAbortException: com.sun.tools.doclets.internal.toolkit.util.DocletAbortException: com.sun.tools.doclets.internal.toolkit.util.DocletAbortException: com.sun.tools.doclets.internal.toolkit.util.DocletAbortException: com.sun.tools.doclets.internal.toolkit.util.DocletAbortException: com.sun.tools.javac.code.Symbol$CompletionFailure: class file for javax.portlet.PortletResponse not found
It says that javax.portlet.PortletResponse class is not found, so I tried to add javax.portlet as a dependency to the javadoc plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
</plugin>
But, I still get the error.
Then I tried to add portlet-api dependency to the pom dependencies section, along with other maven dependencies. Then it worked.
But, my final war file does not depend on portlet-api, so I do not want it to end up in WEB_INF/libs of my war file.
So, how can I fix this build issue without making portlet-api a dependency of my final war file?

How to determine version of the actually installed maven-gpg-plugin?

As documented on this page, here is the maven-gpg-plugin block as used in the POM for all three of my projects:
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
How can you tell the version of this plugin that is actually installed on my computer? Is the fact that 1.5 seems to work good enough?
Thanks.
there could be multiple installed you are interested to know which one is being used effectively you need
mvn help:effective-pom
this will render effective pom.xml and you can figure out which version is effective

Categories

Resources