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
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?
In my project I need to reference to the package installed by Maven to local repository. I've added the dependency to pom.xml, but the project doesn't want to build as it wouldn't even see the package. Here's the pom.xml fragment with dependencies:
<dependencies>
...
<dependency>
<groupId>libraryweb</groupId>
<artifactId>classes</artifactId>
<version>1.0SNAPSHOT</version>
</dependency>
</dependencies>
When I try to import the package "libraryweb" I get
Cannot resolve symbol 'libraryweb'
error. What can I do to use the package?
Edit: Intellij prompts me classes from the package when I try to use them, but I still get "cannot resolve symbol" error.
Note that groupIds and package names are not necessarily the same.
So while your JAR is installed under a certain groupId, artifactId and version, the actual package that you need to import in your Java code may have a different name.
In doubt, unpack the JAR and look at the directory structure.
I solved the problem by linking the .jar file with IntelliJ projects settings instead of using Maven to do it.
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.
I have a project that has some dependencies. Some of those dependencies are Mavenized and some of them aren't.
Two dependencies use the same class, but from different packages, one from Java Libs and the other one from GWT libs. This makes the app crash.
MyPackage Depends On: Package A
MyPacakge Depends On: Package B
Package B and Package A are conflicting.
Currently the only solution I've found was to exclude one the conflicted dependencies.
Is there any plugin for Eclipse-Maven or any workaround to easily solve this?.
Thanks.
In my opinion,2 or more classes with the same package path and same class name mixed in the class path,the first class loaded will come into use,and the later ones are all ignored.And no exception or even currution will happen.
This jvm class loading rule is frequently used in enterprise app to fix bugs quickly.Make a jar named with name of 'a_name_yyyyMMddHHmmss.jar' to replace the mis-coded java class with out compiling the whole projects and upgrading.
Would you please add your exception log or something?
I have several advise:
Make sure the GWT version and jdk version the 'same'/compatible.
Use the "Dependency Exclusions" of maven pom config.Refer here.
I'm having hard time to setup springframework code in Intellij.
I git-cloned springframework project from github, and ran ant task to get all the libraries into ivy-cache directory.
I found "spring-framework.ipr" file for intellij project, and opened it.
Unfortunately, some of the libraries are not correctly mapped to the jar files or missing. So I cannot compile the codebase in IDE.
I also tried importing as eclipse project into intellij. Jar file reference seems ok.
But there are compilation errors in OXM module. Some test classes have reference to auto generated classes such as "~.samples.flight.FlightDocument", "~.jaxb.test.FlightType", and they don't exist(ant test goal generates them in target dir).
It seems same problem happens in STS.
I referenced this blog post:
http://blog.springsource.org/2009/03/03/building-spring-3/
Any good idea to setup spring code in intellij?
I use intellij v11.
git branch: 3.1.x
git commit: e8fc90ce3e4554f14eaa86ce05591249d3fe62fa
Compilation error example:
.../org.springframework.oxm/src/test/java/org/springframework/oxm/xmlbeans/XmlBeansMarshaller Tests.java
Error:(29,42) package org.springframework.samples.flight does not exist
Error:(30,42) package org.springframework.samples.flight does not exist
Error:(44,9) cannot find symbol class FlightsDocument
Error:(44,58) package FlightsDocument does not exist
....
Thanks,
problem solved.
"spring-framework.ipr" is the one for intellij.
lesson learned:
simply wrong version of junit was referenced in spring-framework.ipr file.
when ant build failed middle of the test, subsequent module won't be built. so, required libraries won't be downloaded into ivy-cache/repository.
"ant jar" goal will not download test related libraries since the goal doesn't run tests
After all the tests passed and manually fixed junit reference, intellij finally has no errors.