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.
Related
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?
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.
I have a custom dependency for my project, api-client. This dependency is used to connect among multiple modules within my project.
The problem is, if I make any changes in my api-client dependency and I produce a .jar file using the below command:
mvn install -Dmaven.test.skip=true
I will place that .jar file in my .m2 repository manually. Afterwards, if I try to run other modules which depends on api-client, those modules
would throw lots of compilation errors. (Previously, all ran successfully.)
Some of the sample errors are as follows:
[ERROR] /C:/Local/core/src/main/java/com/core/service/impl/DBSClaimServiceImpl.java:[33,39] C:\Local\core\src\main\java\com\core\service\impl\DBSClaimServiceImpl.java:33: package org.apache.commons.lang3 does not exist
[ERROR] /C:/Local/core/src/main/java/com/core/service/impl/DBSClaimServiceImpl.java:[33,1] C:\Local\core\src\main\java\com\core\service\impl\DBSClaimServiceImpl.java:33: static import only from classes and interfaces
[ERROR] /C:/Local/core/src/main/java/com/core/model/Dealer.java:[9,39] C:\Local\core\src\main\java\com\core\model\Dealer.java:9: package org.apache.commons.lang3 does not exist
[ERROR] /C:/Local/core/src/main/java/com/core/model/Dealer.java:[9,1] C:\Local\core\src\main\java\com\core\model\Dealer.java:9: static import only from classes and interfaces
[ERROR] /C:/Local/core/src/main/java/com/core/resource/settlement/flatFile/RecordType1ClaimInformation.java:[10,39] C:\Local\core\src\main\java\com\core\resource\settlement\flatFile\RecordType1ClaimInformation.java:10: package org.apache.commons.lang3 does not exist
All the packages are available in my local repository, but still, it is not recognising them. I am unsure what exactly the problem is here.
Below please find entries that I have in one of the module:
<api.version>1.0.245</api.version>
<api.client.version>1.0.292</api.client.version>
The problem started once I changed the above version (api.client.version). After that, an old version also throws the same error.
To resolve transitive dependencies, other modules do not just need the api-client.jar, but also a generated pom.xml which declares what other jars are needed to use api-client.jar.
There are multiple ways to fix this, but the description of your environment is not detailed enough to tell how best to fix this.
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
I'm new to IntelliJ and Java but I have a fair bit of TeamCity experience, mostly building .Net projects.
I have created a very simple Android Library project in IntelliJ with basically a single class that uses RxJava (Reactive Extensions for Java). I have added the Rx library in IntelliJ using Project Structure -> Libraries -> From Maven. The actual library I have added is com.netflix.rxjava:rxjava-android:0.19.6 which pulls in com.netflix.rxjava:rxjava-core:0.19.6.
This works brilliantly and my project compiles within IntelliJ without even having to install Maven. Nice job, JetBrains.
However, when I try to build the project in TeamCity using the IntelliJ-IDEA runner, the project doesn't compile. Bad JetBrains!
I get errors on all the references to rx.*, which as I said all worked perfectly on my workstation. The errors from TeamCity look like this:
C:\BuildAgent\work\eefd62e2c3082b56\src\com\example\TigraAndroidUtilities\ObservableModel.java:3: package rx does not exist
import rx.Observable;
^
C:\BuildAgent\work\eefd62e2c3082b56\src\com\example\TigraAndroidUtilities\ObservableModel.java:4: package rx.subjects does not exist
import rx.subjects.BehaviorSubject;
^
C:\BuildAgent\work\eefd62e2c3082b56\src\com\example\TigraAndroidUtilities\ObservableModel.java:18: cannot find symbol
symbol: class BehaviorSubject
location: class com.example.TigraAndroidUtilities.ObservableModel
private BehaviorSubject modelStream;
^
C:\BuildAgent\work\eefd62e2c3082b56\src\com\example\TigraAndroidUtilities\ObservableModel.java:63: cannot find symbol
symbol: class Observable
location: class com.example.TigraAndroidUtilities.ObservableModel
public Observable toObservable()
^
C:\BuildAgent\work\eefd62e2c3082b56\src\com\example\TigraAndroidUtilities\ObservableModel.java:28: cannot find symbol
symbol: variable BehaviorSubject
location: class com.example.TigraAndroidUtilities.ObservableModel
modelStream = BehaviorSubject.create(modelData);
^
C:\BuildAgent\work\eefd62e2c3082b56\src\com\example\TigraAndroidUtilities\ObservableModel.java:65: cannot find symbol
symbol: variable Observable
location: class com.example.TigraAndroidUtilities.ObservableModel
if (completed) { return Observable.empty(); }
^
Here's what I've tried:
Considered using the Maven build runner instead; but the project doesn't have a POM file so it's not a Maven build.
I've tried installing Maven on the build agent, that doesn't seem to make any difference and I didn't need to install it for IntelliJ to work locally so I can't see why it would be needed.
There is a path macro called MAVEN_REPOSITORY in the IntelliJ build runner settings and I've tried setting that to various different values, no luck.
I've looked at JetBrains' documentation for the IntelliJ runner and as far as I can tell, I've configured my build step correctly. Clearly I'm missing something though.
This is all a bit frustrating, I've been tinkering with it hours but nothing seems to work and basically I have no clue what I'm doing wrong. I must have missed something somewhere. How can I get this build working properly in TeamCity?
As of TeamCity 9.1, its IDEA runner can't build Maven modules any longer, nor can it auto-download external artifacts from Maven Central.
Basically, what you need is:
Download external artifacts, one by one, using TeamCity Maven runner and maven-dependency-plugin, as described in this answer., e. g.:
mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.0:get com.netflix.rxjava:rxjava-android:0.19.6
You'll need as many Maven build steps as the number of dependencies in your IDEA project, and these steps must precede the IDEA runner build step.
At the build configuration level, set the system.path.macro.MAVEN.REPOSITORY system property to %env.HOME%/.m2/repository.
That's it.
Happy building!