Intellij-IDEA selects the wrong maven dependency - intellij-idea

I have used IDEA for some time and recently I updated to version 2018.1.1 from 2016.3. So it seems as if IDEA have gotten smarter, but not to my pleasure I am afraid.
So basically I have started to run into a lot of troubles lately. I have for example noted that when there are possible issues with the unit tests (eg. TestNG tests) there are currently two things that happens
1) Maven cannot find the jar (which btw builds perfectly from command line using mvn clean install)
2) Maven reverts to the latest working jar.
If I then try to reimport, I will go directly to (2). I also get weird error where commercial libraries such as guava generates errors.
I have never seen this until I upgraded IDEA Intellij. Anyone that have an suggestion on that might cause this and how to solve the problem.
The behavior I want is that the version marked out in the pom is imported with all the possible flaws, like it use to do. Then I can find the errors and fix them. I should also point out that, mvn clean install -Dmaven.test.skip works perfectly from command line, so not dependency issues with production code.
maven 3.3.9
jdk 1.8_172-b11
EDIT
I must mention that I use the "import maven projects automatically" feature here, which might explain (2), but I can still not see how this issue appears in the first place. Apart from changing IDEA version previously I have not had any problems in finding SNAPSHOTs.
EDIT 2
So the problem was indeed a pom error. I am not sure how eclipse managed to find the "correct" file (which was btw, not the correct file). After updating the pom it all worked out. I will not mention this here, since the behavior was a bit obscure (and I am not sure I understand it really). It have something to do with versions of the libraries, dependencyManagment, submodules and dependencies from submodules.
BR
Patrik

Related

Intellij - work-around for IDE not building module on Run/Debug

I have a pretty large project, of which the Selenium/Cucumber part is integrated, and belongs to me.
No, after upgrading to Intelij 2022, I find that things have changed to the worse. Since I only bother about the module containin cucumber/selenium tests, I have been used to just clicking Run or Debug on each Run/Debug configuration to get my changes built, and the Cucumber/Selenium tests run locally on my computer.
This doesn't work anymore, and absolutely 100% of all help/support I have found on the net is unhelpful. The problem is that when I make a change in the code and click Run or Debug, the module (cucumber, where all the Cucumber/selenium tests resides) is not built. So, it keeps running the previously built code when I'm working on debugging/fixing tests.
The solution has been to first build the module containing the tests, then run/debug the test(s). Even though the run/debug configuration DOES have "Build" before launch. But this is tiresome, and a total waste of time.
So, what I'm wondering is: Can I tailer a terminal command to do all this? That is, build a specified module, then Run or Debug a Cucumber test.
Any help/hints are appreciated. I'm experiencting the usual "me" problem, where it seems that everyone else in the world has something working, while the same solutions doesn't work for me.
EDIT:
I tried the solution offered below in the comments: Deleted the .idea folder, reimported all Maven modules and reconfigured the project. It seemed to work on the first run, but then it went back to not building before launch.
You can try to change Select Run/Debug configuration in idea. Change Build to Build Project. It worked for me.

"mvn clean install" failed in command line, but passed in intellij

New to java and intellij, pls forgive me if i cannot describe the issue clearly.
Brand new install of intellij, brand new import of the java project.
From beginning, seems the project builds fine in intellij, in the GUI there's that clean/compile/verify/install/... life cycles. I click clean, then install, it triggers the unit test and all passing. Now i go to the project root in the command line, "mvn clean install" also passing.
Now i make a change to a resource file, *.sql which is used for in-memory db setup for unit test. i click clean, then install, still passes successfully.
Now i go to the command line again, "mvn clean install" fails in unit test.
I'm so confused now, either way i'm doing the "clean", what's the cause and how should to fix it pls ?
BTW, after working in visual studio for so long, this java and intellij is giving me heart attacks, why the build system in java is so hard and messy ?
Your project is likely configured differently from the maven pom.xml file. When the two aren't configured the same, you'll have problems. I would guess that some dependency is configured correctly in the IntelliJ Project file, but not in the pom.xml. I usually have the reverse problem. I use only the pom.xml to specify dependencies, and rely on the maven plugin to refresh the project (eclipse).
With IntelliJ, it's been a few years, but I remember the same idea. Try deleting the project file, and importing an existing maven pom file. Then modify your dependencies using only the pom.xml and not IntelliJ's project interface. If the pom.xml is correctly defined, the project import will work first try. That heavily depends upon the previous developer working with the project.
Maven is actually a very powerful (if not quirky at times) build tool, and the differences between execution on command line or "inside" IntelliJ are usually simple to explain.
Please check:
you are running the same version of maven (check command line with -version, compare to intellij setup in settings
you are using the same local .m2 folder (local repo) for maven vs intellij
you are not running with any "Profiles" in intellij (check that none are ticked).
you are not skipping any tests because they end with "IT" (meaning Integration Test)
These are the common reasons for differences.
If you post a log of your failing build we might be able to help more.
ok, my friend found the issue, in Maven settings in intellij, there's a "Runner" page, there's a "Skip test" there. In my case it's checked, so the run in intellij skipped unit test (which should fail) and did all other stuff, made it looks like it's passing.
Still several puzzles to me, but this "Runner" -> "Skip test" fixed the issue.
Pretty upset with intellij.

FindBugs in Intellij Idea doesn't refresh the result

Intellij Idea - version 14.1.3. Installed Findbugs plugin (v.0.9.997) and run once.
After fixing found bugs, I run it again but unfortunately the plugin still shows the same list of errors, ignoring my changes. Some of errors even point to the nonexisting lines (which I deleted).
Tried to invalidate IDE cache (with restarting), nevertheless it didn't help.
Could you please assist?
Unlike IntelliJ IDEA's built in inspections, FindBugs uses the class files to find problems, not the source files. Make sure you compile your project after fixing the problems, otherwise FindBugs will keep seeing the problems in the out-of-date class files.

IntelliJ 12 + Gradle 1.3 - Basic Gradle syntax seems non-functional

I am attempting to play around with Gradle integration in IntelliJ Idea (Ultimate) v12.
It seems even if $GRADLE_HOME is configured properly, basic syntax such as 'apply', 'dependencies', etc. is not recognized.
I would seem like the solution should be something simple. Any help is appreciated.
IntelliJ IDEA doesn't currently offer syntax completion for Gradle build scripts. All you get is the standard Groovy support.
I was having the same problem until this morning. I did the following steps and it solved itself:
added the root build.gradle file (we have several) to the JetGradle tab and refreshed
updated to IDEA 12.0.1 (it restarts and reindexes)
I think doing the first one and restarting may be enough, but I'm not sure.
I'm using Intellij 13 and have had similar problems. What I noticed was, creating a new Project from Intellij (i.e. new Groovy Project or Gradle project), I get the syntax error markers. I also have noticed it didn't do a good job pulling in Gradle dependencies.
On the other hand, if I Import a Project through an already created build.gradle file, the syntax error markings go away and the dependencies seem to play more nicely. Not sure if this works for you.
With Intellij 14 and Gradle 2.3 I found that adding {$GRADLE_HOME}/lib and {$GRADLE_HOME}/lib/plugins as libraries in my project settings got rid of all the warnings like "dependencies cannot be applied to groovy.lang.Closure".

Problems with Maven 2

I recently started to use Maven2 in one of my Java web application projects. Now I had many issues with it, some times project fails to build for no apparent reason and then it suddenly starts to work when nothing was done at all to project. Or some times our project members must delete project from their harddrive and download project again from SVN. There seems to be many very odd bugs in Maven in eclipse, but there some issues I would like know if it is possible to solve this issues.
1) I have understood that Maven2 should be able to get dependencies for added jars, but when I add a new dependency in Eclipse, it fails when I build it, it says dependecies are missing. How can I make maven to download those missing dependecies automatically?
2) I have Tuckey UrlRewrite Filter in use, but public repositories have only old version of this dependecy, so when I use this old version (3.1 when I need 3.2). How can I include this to project? We have many programmers in this project, so setting up local repository would mean that all our programmers would have to install that local repository.
Now I had many issues with it, some times project fails to build for no apparent reason and then it suddenly starts to work when nothing was done at all to project. (...)
Ok and what is the point of this free rant? I use Maven and my builds are 100% reproducible, there are well known practices to follow to achieve this. Maybe you're just not following them. Anyway if you're not happy with it, what can I say, don't use it.
I have understood that Maven2 should be able to get dependencies for added jars, but when I add a new dependency in Eclipse, it fails when I build it, it says dependencies are missing. How can I make maven to download those missing dependencies automatically?
I think you misunderstood, Eclipse won't guess what Maven coordinates to add if you don't provide the required informations for them. Dependencies must be declared in the POM, either by editing the POM manually or by using m2eclipse wizards.
And if this is what you did (and if I misunderstood the question) then please provide the <dependency> declaration and the exact error trace.
I have Tuckey UrlRewrite Filter in use, but public repositories have only old version of this dependecy, so when I use this old version (3.1 when I need 3.2). How can I include this to project? We have many programmers in this project, so setting up local repository would mean that all our programmers would have to install that local repository.
This question has already been asked several times, see for example Maven, how to add additional libs not available in repo where I suggest two possible solutions (use a corporate repository like Nexus or a "file-based" repository, the former suggestion being the preferred one for a long term solution).