Unknown Java maven compilation error: R1549aadb - java

Whilst modularizing and migrating a Java 8 project to Java 17 an unknown maven error has been encountered.
The project has non-modular dependencies.
The regular classes and test classes (JUnit5) compile and run fine through Eclipse (without invoking maven).
The regular classes compile fine with maven, however when maven compiles the test classes (JUnit5) errors such as are reported:
[ERROR] /C:/some/path/to/a/source/file.java:[11,15] cannot access org
R1549aadb
Where org is assumed to be the first portion of a package name, other examples encountered include java, javax.
The line number always seems to correspond to an import statement. in this case line [11] was: import org.junit.jupiter.api.Assertions;
Anyone familiar with this kind of error?
Does anyone know what R1549aadb refers to?

Related

Kotlin compile works, mvn compile and intellij run-app does not

I'm having a very odd issue which I cannot explain.
I've made an artifact using gitlab ci, which I'm now importing as a dependency in another project using maven.
When I import this into the new project, I get some very strange behaviour in regards to the classes in the imported dependency. These behaviours are as follows:
In Java files (Test.java), the package is found and Intellij reports no issues. I can even navigate to the source code in the library.
In Kotlin files, Intellij complains that this package cannot be found. I can't navigate to the source code as the IDE says "unresolved reference". If I do a maven artifact search, it is found but adding it makes no difference as the dependency is already in my project.
maven compile/package also complains that this package cannot be found
The dependency is definitely present:
I've tried the following:
Reimporting maven projects
Invalidating caches
Changing java versions, 8 - 11
The artifact is written in java 11 if that makes any difference.
Please help, this is driving me crazy.
Thanks to those that answered!
After a long 24 hours of debugging, it turns out the issue is related to how intellij & maven look for packages in dependencies.
I was compiling with the spring-boot-maven-plugin which was building the jar with a top BOOT-INF directory, and the package structure below this.
This meant both intellij and maven were confused as they seemed to be able to find the package but not build it.
I've since removed the plugin and left now just compile with the kotlin-maven-plugin which has the package structure at the top level of the jar.
Now when I import into a project, the project can find and compile this dependency.

Java 11 unnamed module issue when using Maven model

So, I'm trying to migrate a tool from Java 8 to Java 11.
I did the first step to make it work without modules and the code compiles successfully.
Now I'm trying to add the module-info.java, and I first faced issues because of the libraries used in my tool. Some are already compatible with Java 11 (e.g. Lombok) but some others are not, so I'm trying to import them using the requires and the artifactId name.
But I seem stuck because of my Maven model & Maven model builder dependency as I get the following error when building:
[ERROR] the unnamed module reads package org.apache.maven.model.merge from both maven.model.builder and maven.model
[ERROR] module maven.model.builder reads package org.apache.maven.model.merge from both maven.model.builder and maven.model
[ERROR] module maven.model reads package org.apache.maven.model.merge from both maven.model.builder and maven.model
What should I do for this kind of error? It seems I need both (build still fails if I comment one or the other). Does it mean I cannot add modules to my tool because of my dependencies?
N.B.: The libraries are set to their latest version (i.e. 3.6.3)
I "fixed" this using the maven-exec-plugin as described in the answer to this question.
Edit: When running the main class through the maven-exec-plugin, the compiler does (for some reason unknown to me) not complain anymore about the conflicts.

Java 9 migration javax.annotation

So i try to migrate my project to Java 9 but the process seems not so easy as i thought it would be. I kept getting some errors about invisible packages that i could fix with the following argument in my pom:
<compilerArgs>
<arg>--add-modules</arg>
<arg>java.se.ee</arg>
</compilerArgs>
But i still get the following error:
cannot find symbol
[ERROR] symbol: class Priority
[ERROR] location: package javax.annotation
any help would be appreciated
I'm not sure where javax.annotation.Priority comes from, but a solution analog to getting JSR 305 running on Java 9 should fix your problem: Instead of adding the (deprecated) Java EE module java.xml.ws.annotation (which you do indirectly by adding java.se.ee), you should instead add the javax.annotation package from an external artifact, namely javax.annotation:javax.annotation-api.
If you modularize your code, that solution no longer works and you have to start patching modules. Or, even better, move away from solutions that require non-JDK classes that pretend to come from java or javax packages because that will always cause problems.

Groovy code fails to compile

I have a groovy class which imports some external packages defined in the pom (maven dependency). I am using IntelliJ 2016.1.3 Community Ed, Java 1.8_92, and Groovy 2.4.6 as the global library.
I've created two classes within my project to test the problem. One is a .groovy file and one is .java.
Classes
The maven dependency is
<dependency>
<groupId>org.mobicents.sipunit</groupId>
<artifactId>sipunit</artifactId>
<version>2.0.1</version>
</dependency>
Now the problem is the .groovy file throws an error during compilation while the .java does not (both use the same imports and packages). The weird thing is the groovy class can auto-import the required packages when declaring the objects which means it can "see" which packages are needed while writing the code but not during compilation.
I've been struggling with this problem for two days now. I hope someone can help.
Imports
import org.cafesip.sipunit.SipPhone
import org.cafesip.sipunit.SipStack
Compilation error
Error:(11, 1) Groovyc: unable to resolve class org.cafesip.sipunit.SipPhone
Error:(12, 1) Groovyc: unable to resolve class org.cafesip.sipunit.SipStack
As an added note, I have tried the solution here but it doesn't work.
Groovy and IntelliJ - getting code compiled

Is there a Maven plugin or configuration that will verify the Java package declaration matches the source directory?

I've ran into an issue with Maven a few times now where the build does not fail if there's an inconsistency between the package declaration and the path of the source file. From other Stackoverflow questions, there are several examples that shows Eclipse catches this type of error no problem and explains why Maven doesn't:
Eclipse says package declaration does not match expected package ""
Eclipse: The declared package does not match the expected package
Maven + Java package declaration
There are a few different issue that can arise when Maven doesn't catch this inconsistency including run-time failures to load classes or unit tests omitted from a build without flagging any errors.
Although Maven doesn't catch this with the compiler, is there any Maven plugin out there that will validate the package name to the source path? Or possibly some other configuration value that can be set in the pom.xml or settings.xml to get Maven to verify these are consistent?

Categories