Intellij : issue with Mockito library (is it corrupted ?) - intellij-idea

I've been using Intellij and Mockito for years with no issue, but I have a problem on one of my Gradle projects where some parts of Mockito are not recognized as expected, which makes it painful to use.
First of all, when I build my project with Gradle from the command line, I don't have any issue, so it seems to really be a problem with Intellij (I am using latest community edition version, 2020.2.3) .
My first issue was that Mockito was not found at all : thinking that the lib was maybe corrupted somehow, I deleted it from gradle cache folder, where it was stored, so that it would get downloaded again.
Now it seems a little bit better : Mockito is found. However, Intellij will not find the thenReturn method on Mockito.when :
When I try to see Mockito's source code, I get this library source code does not match the bytecode, so maybe there's some inconsistency somewhere.. :
I cleared Intellij cache and restarted, but I still have the same issue. I have tried to clone and build the project in another directory (ie another Intellij project), but I have the exact same issue.
I am using Gradle 6.5.
Mockito version that comes is the 3.3.3, through spring-boot-starter-test (I am using the 2.3.5.RELEASE).
If I override this by declaring myself Mockito, in version 3.2.0 for example, then I dont have the problem anymore.
If I upgrade to Spring Boot 2.4.0, then Mockito 3.6.0 comes, and I don't have the problem..
so it seems to really be related to the Mockito 3.3.3 version I am using..
Is there something more I could do ?

I ended up downloading manually the jar from https://repo1.maven.org/maven2/org/mockito/mockito-core/3.3.3/ and replaced the jar that was used by my project in .gradle\caches\modules-2\files-2.1\org.mockito\mockito-core\3.3.3\ , and it seems to be working.
I will do more tests to understand where the corrupted version got download from.

Related

Intellij-IDEA selects the wrong maven dependency

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

IntelliJ not reflecting Maven dependencies

I recently updated my IntelliJ and I am having a problem with it showing import statements as nonexistent in the classpath despite the project building fine by doing mvn clean [install|verify] from the command line and the software actually works. So the dependencies are certainly there but the IDE seems to have a bug synchronizing against the pom file. I have tried to Maven --> Reimport multiple times, without success.
Considering that I recently updated IntelliJ (the version is as of 7/15/2017), could this be a newly introduced bug and is there a workaround?
The problem may be caused by a known bug in Maven integration which affects 2017.2 version. This bug is fixed in 2017.2.1 version.
You can find out if it's the case of your problem by searching idea.log for:
java.lang.AbstractMethodError: org.jetbrains.idea.maven.server.embedder.CustomModelValidator$ProxyModelProblemCollector.add(Lorg/apache/maven/model/building/ModelProblemCollectorRequest;)V

Inspecting code on a non-java IntelliJ IDEA project

I'm using IntelliJ IDEA to build a non-java project, it is just a PHP + Javascript project, everything is working just fine but when I try to Inspect all the code in the project (Analyze -> Inspect Code) I get an error:
The JDK is not configured properly for this project. Inspection cannot proceed.
Am I doing something wrong? Do I have to configure an SDK even though the project is not java?
Note: The automatic code inspection for working files opened in the editor is working fine, the only problem is when I try to inspec all the code in the project.
Note 2: I cannot use PHPStorm neither Webstorm.
Thanks.
In my case, I didn't wanted to delete the module since I have a bunch of stuff configured (data sources, dictionaries, http requests) and a lot of code in the shelf (which I believe it's stored along the project/module). I found that you can skip the "delete your module" part and instead just update the module config:
Find the $module.iml file (in my case it's inside the .idea directory) and at the top there's was a line:
<module type="JAVA_MODULE" version="4">
which I changed to:
<module type="WEB_MODULE" version="4">
The issue was fixed and I haven't seen any side-effects but, just in case, you might want to backup the .idea directory.
I raised this over at https://youtrack.jetbrains.com/issue/IDEA-188017 - after some back and forth, the Jetbrains employee helped me figure out that I had a Java module in there.
If you are not using Java, please crate a module of a Static Web type. Now you have a module of a Java type, that is why the error is reported, so such behaviour is expected.
Delete your Java module.
Once you enter in the menu in the screenshot below, find the Static Web type and create your module like that.
Seems like adding a SDK the code analyzer works just fine, even though the project has no single java module.
Maybe it is a bug, so I will report it.
My project's .idea/<project>.iml file had an entry:
<orderEntry type="inheritedJdk" />
I quit Idea, removed the line above from the iml file, restarted Idea and the next Inspection ran without any issues.
I recently ran into this issue with my purely Python project.
After much frustation, I bumped into a rather bizarre solution:
When IntelliJ complained that JDK is not configured, in the following dialog box, I just selected JDK8 (instead of Python 3.7.2 path) and viola! its gone.
My environment was
IntelliJ IDEA 2018.3.4 (Community Edition)
Build #IC-183.5429.30, built on January 29, 2019
JRE: 1.8.0_152-release-1343-b26 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14.2

IntelliJ Datanucleus Enhancer plugin not working

The project I'm developing uses Datanucleus 2.0.3, so I'm using those libraries for enhancement (plugin is configured to use the module dependencies as well). IntelliJ version 12.0.1 on a Ubuntu 12.4 machine. I know the 2.0.3 is ancient history but upgrading it at least now is not an option for me.
From gradle all works fine. I imported by project to IntelliJ and when I ran the tests from junit I got the usual ClassNotPersistenceCapableException so I recalled I need a plugin for this.
I installed the newest plugin (tried both the beta and the last stable version) and configured the plugin to enhance my this one module. I chose JDO and applied, it discovered all the classes annotated for persistence, I rebuilt the whole project, ran the tests again and the same error occurs.
some things I've noticed / checked:
- the Enchaner is ticked in "Build / Datanucleus Enhancer"
- looked for multiple datanucleus jars, but there is only one
- haven't seen any message in IntelliJ in the Event Log saying is has done enhancing (the gradle enhancer logs such a message)
- haven't seen any error messages in IntelliJ saying enhancement failed, I also didn't find any log files outside IntelliJ (should there be any?)
- when I manually added the gradle built classes at the top of the classpath for the test the tests passed - but this is no good
- the module has the following datanucleus 2.0.3 jars on it's classpath: datanucleus-core, datanucleus-enhancer, datanucleus-connectionpool, datanucleus-rdbms and the asm-3.1.jar (the dependencies say it's 3.0-4.0 so this one should fit)
I have no idea why it sees the classes but doesn't enhance them, or maybe it does try and silently fail ... but then I don't know how to diagnose the problem
No other ideas come to my mind, please advise what to check or what to try.

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".