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

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.

Related

Intellij gradle import Issue

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

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:

IntelliJ Idea lombok doesn't appear in intellisense

My problem is that I have lombok used in my project and intellisense doesn't recoginze it's packages and annotations.
What I have done:
dependency added to maven pom.xml (jar appears in "External Libraries")
lombok plugin installed via "Settings -> Plugins -> Browse repositories"
"Enable annotation processing" enabled in "Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processors"
IntelliJ Idea restart with invalidate cache
Project rebuilded
Strange thing is that project get's builded without any errors and works perfectly. I just can't see this package in IntelliJ and it's cumbersome, because a lot of code is "red". My current IntelliJ IDEA version is 2017.3.1.
I've looked up in every post simillar to my problem and tried every method (including reinstalling plugin, doing everything again, changing order in things that were done etc.), but it still doesn't work.
I've solved issue. The problem Was that IntelliJ Idea mistakenly created projects from my main project and they were in conflict. Under "File -> Project Structure" I had 5 different projects which were created from and they still were included in this one that was separate from them. All I had to do was to delete those wrong projects.

spring-boot-devtools doesn't reload dependent modules in multi-module maven project

Before I start, I'd like to say that I already tried the solution proposed in spring-boot-devtools reload of multi-module maven project changes, which didn't work for me.
Problem:
I have a multi-module Spring Boot project of this sort:
The module launcher has a Maven dependency on module GUI. I launch my Spring Boot application from the main method in launcher.
When I run the application and change any HTML file in GUI module, the spring-boot-devtools dependency doesn't do a live reload of these changes for my running application. Not even manual restart of launcher helps. I need to compile GUI manually and then run launcher again.
What I tried:
I tried defining the spring-boot-devtools dependency first in
parent pom.xml, then in GUI module only and then in both at the same time.
I tried adding spring.devtools.restart.additional-paths=../gui in my application.properties file as suggested in spring-boot-devtools reload of multi-module maven project changes. This does indeed trigger the reload (according to the log), but those changes just don't propagate to the jar file of GUI dependency. Also, before I even made this project into multi-module, there was no need for reloading just because of HTML files (nothing is being compiled) and I could see the changes right away.
I use Netbeans GUI if that's of any help. I also tried running the project from command line, with no success. The Maven packaging on all modules is set to jar.
The fact that this works when you configure absolute paths in devtools tells me that this is mainly a work directory issue.
So this means that:
configured paths should be relative to where you launch the CLI
you should configure the same location as a work directory in the run configuration of your IDE (whatever configuration your IDE is using to launch your application should have such an option)
In your case: everything should be relative to your launcher module; this should be as well your work directory in your IDE.
I have no idea how it happened, but upon one revisit it started working without me knowingly changing anything. It doesn't even require the spring.devtools.restart.additional-path property set.
Could've been a problem of Netbeans IDE perhaps? Then again, it didn't work from command line either. If anyone has any explanation for this, it'd still be grateful as it may prevent this problem from happening in future.

Maven JavaFX Cannot find Main Class

I have some problems running my JavaFX8 Project with Maven. Here is the situation:
I create a Maven Java FX application within Netbeans (File --> New Project --> Maven JavaFX Application). Netbeans creates the packages and also creates a MainApp.java file.
Even if I don´t edit anything in this project, I get an error/warning within the properties.
Location: Right-Click Project --> Properties --> Run
Message: One of Run/Debug/Profile Project actions has been modified and the Run panel cannot be safely edited
The project can be built and run for some time, but after I create more packages, classes and stuff like that, I can´t run the application anymore.
It tells me, that it can´t find the Main class.
Message: Error: Could not find or load main class
I found some entries at stackoverflow and google, but none of the solutions seem to work for me.
I read this Topic for example.
One of the solutions is, to set the main class at the properties (Run), but all the fields are disabled. I also deleted the Cache, which didn´t solve the problem. I also checked the typing.
Some other sites stated, that it seems to be a bug, but they had older Netbean Versions. I updated my Netbeans version to 8.2 today.
The only solution at the moment is to create a new Maven JavaFX project and refactor the files to the new project. This works for a couple of hours but in the end the error occurs again.
Does anybody know a solution?
Use Run from the Project, not Run File from the main file. The latter can work on other setups, but not straight out of Maven.

Resources