Issue
I use IntelliJ IDEA 2016.2.4 together with Gradle. When creating an empty project and adding a simple class together with a test class, the project builds fine when running build
target through Gradle, but IntelliJ doesn't see e.g. @Test
annotation for JUnit which is included in dependencies by default.
When hovering over the "missing" class, IntelliJ offers me to add JUnit4 to classpath. After doing this, nothing changes.
I tried invalidating caches and restarting - no success.
Under "External Libraries", there is "Gradle: junit:junit:4.11", and the project builds fine, so I presume it's an issue with syntax highlighting and autocompletion.
I'm not sure if it matters, but in build.gradle
the line that adds a dependency on JUnit (testCompile group: 'junit', name: 'junit', version: '4.11'
) is highlighted with a comment:
'testCompile' cannot be applied to '(['group':java.lang.String, 'name':java.lang.String,...])' This inspection reports assignments with incompatible types
It works fine for other dependencies I tried, i.e. there's no warning like this. But IntelliJ still doesn't see their classes.
These are my first steps with Gradle, so maybe something is still not configured. Does anyone have an idea what might be wrong?
Solution
After trying with Maven and getting the same result, it was clear that it wasn't a problem with Gradle nor JUnit.
Removing the folder ~/.IdeaIC2016.2 did the job.
Answered By - PiotrK
Answer Checked By - Willingham (JavaFixing Volunteer)