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.
Related
I'm having a new problem this morning with my project (it worked fine on Friday). Eclipse seems to be having trouble figuring out it's module / class path, and nothing I'm trying seems to affect it. I'm using the following Eclipse configuration:
Version: 2019-03 M1 (4.11.0 M1)
Build id: 20190117-2133
Oracle JDK 10.0.2
My project is a Java Maven multi-module (those are maven modules, not java modules) project, but does not define any java modules itself (we haven't converted it yet). When attempting to compile it, eclipse throws up its hands and sends the message
"The package java.sql is accessible from more than one module: <unnamed>, java.sql".
While, on the surface, this seems helpful, I cannot find another module that defines the java.sql package, and the only instance of a class from the package (e.g.: java.sql.ResultSet) exists within the JDK system supplied library. This also happens with the javax.xml package with the same error.
I've attempted closing and re-opening eclipse, performing a clean, and a maven update project for everything, to no avail. I've inspected the eclipse .log file, and there's nothing useful in there. Is there anyway to figure out what other module Eclipse thinks it's pulling that package from?
My next step is to delete the entire project and re-import it.
UPDATE: I think I may have found the offender... there's a dependency that declares a couple of classes into the java.sql package, and that's probably borking things up. The specific JAR is net.sourceforge.hatbox:hatbox:1.0.b8, and is a transitive dependency of the com.h2database:h2:1.4.197 jar. Is there any way to tell eclipse to ignore the package from that JAR?
Update 2: Build Path:
I'm not sure I count this as a true solution, but I was able to find a workaround to my problem. I downgraded eclipse from the installed version listed in the question (4.11.0) to the base photon install (4.8.0), and I can now compile and work again.
Adding my project to a new machine and having some struggles importing it in IntelliJ.
Using Java, Spring Boot, Gradle, Maven, latest stable IntelliJ.
My issues are that:
1) The thing is set up with "main1, main2, main3, main4" which I don't think is the correct way for IntelliJ to read the project structure
2) The imports aren't working
import org.springframework.boot.SpringApplication;
returns:
Cannot resolve symbol SpringApplication
How do I remove the project and import it again correctly?
I see this similar answer, but need a little more handholding:
Cannot resolve symbol SpringApplication
Where do I find these directories to delete them? When I import, do I need to run gradlew clean build or mvn import to make sure my dependencies are being imported? It seems to be trying (and failing) to compile the js client files when I run these, which I don't think is correct.
Answer linked in original question should help people with this problem - however, here are the steps I took to resolve:
-delete entire project and clone it down from git again
-import to IntelliJ and specify the build.gradle file (pom.xml if you aren't using gradle), not the root project folder
-run gradlew clean build
-follow chain of prompts for other broken things like lombok, mysql, aws cli
I have a groovy class in maven java project. I upgraded the groovy dependency from 2.4.4. to 2.4.11. If I build the project using maven - it works. However, if I build it with IntelliJ - I get this error:
Information:Groovyc: While compiling MyProject: Conflicting module versions. Module [groovy-jsr223 is loaded in version 2.4.11 and you are trying to load version 2.4.4
java.lang.ExceptionInInitializerError.
When I go to project structre -> dependencies, I see: Maven: org.codehaus.groovy:groovy-jsr233:2.4.4.
When I search all my pom.xml fiels for 2.4.4 - there is nothing left - everywhere I have 2.4.11.
I tried rebuilding all with maven, reimporting maven projects in IntelliJ - nothing works.
Where should I look for this dependency? Is there a quick way to track it?
I have found a solution - Maven Helper plugin (https://plugins.jetbrains.com/plugin/7179-maven-helper). It adds "Dependency Analyzer" tab to pom files view.
Many time this trick works for me.
go to maven widget in intellij idea and click on the refresh icon. it should do the magic.
Recently our project's dependencies artifact name has been changed so as the package names and some classes' names. Now we need to update our project dependencies for our next release. Problem is when invoking eclipse from play console it just doesn't do that if there's any compilation errors which of course is expected. I just want to update the eclipse project settings and fix compilation problems later.
It should generate the projects even if there are compilation problems. You might want to check your sbteclipse version.
There might be a chance that it will not even compile when generating the eclipse files. This could theoretically be triggered by a related sbt issue: compile is executed for discoveredSbtPlugins when the project is not a plugin
So if you are not creating an sbt plugin and have an updated sbteclipse version and still have problems, you could try setting: discoveredSbtPlugins := PluginDiscovery.emptyDiscoveredNames.
I would strongly advise you to first see if the compilation problems are causing the projects not to be created. In the past I have often created projects when I had compiler errors. It will for example not create the project if you have an unresolved dependency.
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.