Intellij gradle import Issue - gradle

I'm having a lot of issues w/ my intellij project to recognize 3rd party libraries I've imported with gradle. Let me outline some steps I've tried.
The code compiles properly in the terminal.
Invalidating and restarting intellij does nothing.
The import, seems to be in the project dependency folder.
I've tried removing the import and resyncing gradle, then adding it back in.
Tried deleting the intellij app and re-installing (I think I may have done this wrong given my configurations were saved upon re-download).
I've tried unticking offline mode, and doing all this in gradlew preferences.
I've tried increasing memory allocation in both intellij and for gradle.
No one else on my team seems to be having this issue.
I have no idea what else to try or where to look. Would LOVE some pointers. Happy to edit. Thanks!
Intellij Version: 2019.1.3

Related

Intellij complaining about JDK location

First Image
Second Image
As I attached 2 images, I am having trouble running my spring boot gradle project written in groovy.
As soon as I open the project, intellij tries to build the project and it fails saying Gradle Sync failed.
Since it is complaining about java home in the jdk setting, I was trying to change the path as my intellij expects. but as soon as I change it, it tells me that it cannot find android sdk location. and I have no idea why it cares about android sdk. This project is about spring batch job using gradle and groovy.
I have been searching why it happens for days now and online is talking about ardroid studio solution. and those solution do not apply to my problem.
Can someone help me with this issue please?
Thank you in advance.
It looks like you are running Android Studio instead of IntelliJ IDEA.
The former doesn't support projects other than targeted for Android, so your project will not work there.
Make sure you run IntelliJ IDEA. You can get it at https://www.jetbrains.com/idea/download/index.html.

spring initializr: Cannot import org.slf4j.LoggerFactory for Gradle projects

I'm trying to learn how to build "Spring Web" web-applications using IntelliJ IDEA, and I'm encountering a very frustrating issue when I try to create a new project using "Spring Initializr".
For some reason when I choose to create a "Gradle Project", Java or Kotlin, I'm not able to import org.slf4j.LoggerFactory
If I manually add the import statement, it doesn't resolve, and if I try to get InteliJ to automatically add the import, it instead adds the following...
import com.sun.org.slf4j.internal.LoggerFactory
This satisfies the editor, but it won't compile. It errors with...
Symbol is declared in module 'java.xml.crypto' which does not export package 'com.sun.org.slf4j.internal'
If instead I create a "Maven Project", either Kotlin or Java, then it works as expected.
I'm keeping the other settings in spring initializr set to default values, Spring Boot=2.4.2, Java=11
IntelliJ IDEA says there are no updates available.
I've made various attempts to manual add the slf4j dependencies to build.gradle (for Java) or build.gradle.kts (for Kotlin), and nothing I've done has made any difference.
I've also tried various different options for Spring Boot and Java version, and again it has made no difference.
Update...
I've confirmed that it only happens on one of my computers, my primary development desktop computer. My laptop is working fine.
I can't find anything that's different between the 2 IDEA installations.
Things I've tried so far to fix it...
Invalidate Caches / Restart
Manage IDE Settings -> Restore Default Settings
Removing and re-adding JDK's
Uninstalling and re-installing IntelliJ IDEA
I've tried everything I can think of to fix this, but the problem persists.
Basically I can't use logging in any new Gradle Spring projects. It just won't load the org.slf4j library.
Update 2...
The nature of the problem isn't exactly what I thought it was initially. It turns out the code compiles and runs just fine with the correct import, but the IDE is reporting it as unresolved.
So it seems it's just an issue with the IDE's intellisense. This seems less serious, but it's still quite inconvenient having the editor incorrectly showing errors.
After identifying that the problem was just with the IDE editor intellisense, rather than with the code dependencies or project, I was eventually able to resolve it by closing the IDE, and then deleting the system folder "C:\Users<user>\AppData\Local\JetBrains\IntelliJIdea2020.3"
After restarting IntelliJ IDEA, the folder was re-created automatically and the issue resolved itself.

how do I fix type mismatch: #ExtendWith(SpringExtension::class) KClass -> Class in intelij?

I'm using intellij community 2018.2 and gradle 4.9 with kotlin 1.2.60
I've just downloaded a springboot2 pack from start.spring.io with kotlin/gradle support + web + h2 + jpa. I am following this official tutorial from spring.
gradle build and gradle test both work fine in command line.
In intellij though, I get the following error from the IDE:
Error:(9, 13) Kotlin: Type mismatch: inferred type is KClass<SpringExtension> but Class was expected
package org.ninrod.blog.blog
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit.jupiter.SpringExtension
#ExtendWith(SpringExtension::class) <-- RIGHT HERE
#SpringBootTest
class BlogApplicationTests {
#Test
fun contextLoads() {
}
}
here is the full source code of the sample: link.
How would one fix this in intellij so that the project compiles cleanly as in command line?
ps: here is a screenshot of the problem in intellij:
well, I uninstalled absolutely everything regarding java and then I installed everything from zero, removed all configurations, everything. Then it worked.
What you have is correct. I could not reproduce the error as shown in the screenshot below. And I was able to run your test without issue. So it is a false error. You can verify this by confirming the project builds via Gradle either from within IDEA of from the command prompt.
Try the following:
From the Gradle tool window, click the "Refresh all Gradle projects" button
From what I am seeing, and from my experience, I don't think think this will resolve the issue. But it is a quick hit and worth a wuick try.
It's possible the IntelliJ IDEA caches are corrupted. Go to *File > Invalidate Caches / Restart *. In the dialog window, click "Invalidate and Restart". After IDEA restarts and the project opens, wait for it to finish reindexing the project (watch the progress at the bottom). Once the reindex is done, see if the issue is resolved.
I suspect this will resolve the issue.
If the above does not work, then it's possible something is not configured correctly. Try recreating the IDEA project. Close the project, delete (or archive) the .idea directory and any *.iml files. Then import the project by selecting the build.gradle file. If you are not familiar with this, watch the "Working with Gradle in IntelliJ IDEA" video on the IntelliJ IDEA documentation page
Lastly, make sure you are running the latest version of IntelliJ IDEA (v2018.2), that was released two weeks ago. It is what I'm running. You using a lot of the latest and greatest tech (JUnit 5, Kotlin, Spring boot 2.x with Spring 5.x), so an older version of IDEA may have a problems. Finally, even though what you have worked for me, I'd recommend upgrading to the latest version of Kotlin (v1.2.60) in your gradle.properties
I do not get the error and can run the test:

How to fix gradle eclipse plugin to use correct JRE when importing gradle project?

Currently, I can run ./gradlew eclipse and create the eclipse project and that works great in that it uses JavaSE-1.8. Unfortunately, I have 12 projects and don't really feel like loading each one at a time.
The issue though is when I use the gradle eclipse plugin and import the project, it decides to use JavaSE-1.7 which I did 'used' to use. I can't seem to find a quick setting in the gradle plugin, though it would be even nicer if I could just put the info in the build.gradle file for everyone to use.
The following code blew up in my face when I imported the project..
https://issues.gradle.org/browse/GRADLE-3100
Well, the .remove method blew up. Removing that resulted in ending up in 1.7 even though I put 1.8.
I am using gradle-2.11-bin.zip
UPDATE: I removed the '' replacing with single ' so that it doesn't throw an exception but still loads 1.7. To work around this issue, I load with gradle plugin and then run ./gradlew eclipse and then collapse all projects and using the shift key, I then select all projects and refresh and it moves to 1.8 (so the gradlew eclipse works while the gradle plugin doesn't :( they must be different code path).

Intellij Debugging picking up old version project files

I am debugging code in Intellij. I use maven to build the project and there are various versions of the project sitting in the local .m2 repository. Intellij keeps on picking the old version of the code from the previous snapshot of the project when I start debugging. How do I make IntelliJ debug the latest code from the local repository?
You can tell Intellij 2016 to ask you each time which source code to step through.
File->Settings->Debugger
Show alternative source switcher
Try removing .jar and .war files that contain your code from your ~/.m2/repository/
For me the issue is that I built something and it is now registered in Maven under what Maven considers a newer version, but isn't what I was currently working on. I compiled, say, version "2.1" to debug something and then went back to working on "sand-box-idea-SNAPSHOT". I keep thinking why isn't Intellij picking up my latest sand box change but it's because it's deferring to the Maven version 2.1 which Maven assumes is better than 'sand-box-SNAPSHOT'.
It may be that you have some plug-ins interfering with IntelliJ's build process. I know that the Google Protocol Buffers Plugin can cause my Intellij to be unable to detect dirty classes that need to be re-compiled.
I've met similar behavior, maybe it can help you :-)
I developed app (using maven) and during the time I change output packaging from jar to war. Maven repository than contained both versions, jar and war, because maven does not remove old jar when you change it. As project pointed to mvn repository, it still used old reference to jar but new version within war was updated.
I was really upset as maven compilation and tests worked fine but Idea used me old version. I've had rebuild idea project and it worked later fine.
I have seen this very recently after upgrading from IDEA 13 to IDEA 14. It seems like launching configurations created in IDEA 13 are no longer automatically triggering a mvn package prior to launch.
In order to fix this I manually added a mvn goal in the "Before Launch" dialog.

Resources