IntelliJ downloads Gradle dependencies but cannot find them during compile - intellij-idea

IntelliJ downloaded the dependencies listed in my build.gradle file and they show up in the External Library, but IntelliJ fails to find them during compile. It just throws a bunch of "package x does not exist" and "cannot resolve symbol". Under the Project Structure -> Modules -> Dependencies they all show up and are listed as compile.
If I try to build it with Gradle it's successful, so it's just IntelliJ. Any ideas?
If it's important, I'm using this on a Mac.

Found the answer. IntelliJ was treating Main and Test as modules with no dependency related to the project itself and all of the library dependencies were stored at the project level.
I killed off Main and Test as modules and it sorted itself out.

Related

Error trying to add junit dependency to maven in IntelliJ

I am using Intelli J as the IDE and maven(3.3.9) as my build tool. After I completed my code in Java I was trying to add junit dependency to my pom.xml but maven doesn't seem to recognize the dependency. I came across a few other related questions on this issue but on trying all possible solutions exhaustively the problem still seems to persists.
My pom.xml currently looks like:
Following are the possible fixes I tried to alleviate the issue:
Downloading Library from Maven Repository from Project Structure
Specifying the junit dependency through the Project Structure (File > Project Structure > Libraries > New Project Library (from Maven)). I searched for junit and chose junit:junit:4.11 but I get "No files were downloaded"
Makes changes in the Project Setting for Maven
I went to File > Settings > Build,Execution,Deployment > Maven and I checked Use plugin directory and changed maven to the appropriate location. It looks like follows:
Following that I also went to File > Settings > Build,Execution,Deployment > Maven > Importing and checked Import Maven Projects automatically.
Running maven
Then I also ran maven clean install which ran with success after downloading some files:
Re-importing All Maven Projects
I also re-imported all maven projects from the Maven Projects tab on the right but I end up with unresolved plugins and the an error popup saying "Failed to read artifact descriptor for junit:junit:jar:4.11" when I hover over the red-lines.
Can someone tell me anything else I might have missed if you have ever encountered the same before ?
Thanks!

IntelliJ Gradle "Unable to find Method"

The Error:
Failed to sync Gradle project '-'
Error:Unable to find method 'org.gradle.internal.logging.progress.DefaultProgressLoggerFactory.(Lorg/gradle/internal/logging/progress/ProgressListener;Lorg/gradle/internal/time/TimeProvider;)V'.
You can see, a constructor inside a class, which is found in the logging jar (gradle_home/lib/grade-logging-version.jar) is missing.
So, I think the Class-Path does not contain this jar file.
Gradle Version: 3.5
Running using the Command Line works.
I have already tried this:
Gradle sync failed: Unable to find method
to-find-method, it does not work for me.
I have tried to use different versions.
I can't see any difference when enabling
"Use default gradle wrapper"
"Use gradle wrapper task configuration"
"Use local gradle distribution".
I had the exact same problem today.
The only way I was able to get it to work was to remove my IntelliJ IDEA IDE, get the latest from the website (with JDK) and put it in a new folder (i.e. no overwriting existing files).
After that, I deleted the .idea folder from the project and reimported it cleanly into the "new" IntelliJ.
I suspect upgrading IntelliJ from Version <= 2016.x caused the issue, since a new installation / clean extraction from archive caused it to work on the fly.

Conflicting project in Xtext mwe2 workflow

I have a Xtext DSL that builds successfully from inside eclipse and maven and is included in a complex multi-plugin RCP application.
Yet, whenever the MWE2 workflow is executed the log is full of warnings of the form:
[INFO] 281 [main] WARN lipse.emf.mwe.utils.StandaloneSetup
- Skipping conflicting project org.eclipse.e4.core.contexts
at 'archive:file:/C:/userdir/.m2/repository/p2/
osgi/bundle/org.eclipse.e4.core.contexts/1.3.100.v20140407-1019
/org.eclipse.e4.core.contexts-1.3.100.v20140407-1019.jar!/'
and using 'archive:file:/C:/userdir/Documents/projects/projectdir/
resources/project/plugins
/org.eclipse.e4.core.contexts_1.3.100.v20140407-1019.jar!/' instead.
Some of these warnings, like the above, are about a conflict between the local .m2 folder and a project folder, while others show a conflict between two project folders.
Question:
How do I get rid of these warnings?
My guess is that the project is misconfigured somehow including dependencies to some jars twice.
Yet, at the moment I have no idea which dependencies are used by MWE2 during execution causing these warnings.
Is there any way to get an overview of the consulted dependencies or to debug this stuff?

IDEA cannot compile java file in gradle project

I am build a gradle project and run compileJava task everything is ok. But i right click one java file and 'Compile xxxx.java', i get some error.
Error:(3, 25) java: package com.jpf.ms.entity not exists
...
IDEA version: 14.1.4
Make sure your settings.build references that package, and refresh your dependencies as shown here before running gradle tasks.

How to get IntelliJ to associate Gradle sources with build.gradle?

When writing Gradle scripts for my Java project, specifically, when writing build.gradle files, IntelliJ does not recognize the Gradle API.
For instance, Gradle methods calls like apply, dependencies configure appear with a black line under them and it is not possible to navigate to method declarations, there is no auto-completion etc.
I managed to work around this by adding compile gradleApi() to the build's dependencies block. However, I don't want to have this explicit dependency in my code.
I tried editing IntelliJ's project structure and add a dependency on a Gradle library (tried gradle-core and gradle-all) to my modules, but that seems to have no effect.
Is there a way to make IntelliJ associate all build.gradle files with the Gadle sources?
I solved this problem as follows:
As mention in already posted answers, configure gradle
update gradle/wrapper/gradle-wrapper.properties file
change bin to all in distributionUrl i.e.
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
to
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip
OR
[optional] If you are using old version of gradle wrapper and wanted to upgrade, then execute
./gradlew wrapper --gradle-version 6.8.3 --distribution-type all
Update gradle task (if present in build file)
wrapper {
gradleVersion = '6.8.3'
distributionType = Wrapper.DistributionType.ALL
}
Before importing the project to IntelliJ-Idea IDE, update build.gradle and add java and idea plugin to the plugins list
plugins {
id "java-library"
id "idea"
}
From a terminal, execute ./gradlew clean build idea or simply ./gradlew idea
Import project to IntelliJ idea.
Go to Preferences --> build,Execution,Deployment --> BuildTools --> Gradle
You can see
Restart IntelliJ idea IDE.
So above we have configured both of the options so choose either of them, except the specified location option. That's it.
Before
After
Autocomplete functionality as mentioned in this answer.
I had similar frustrations with Grails 3, which defines and runs a wrapper task when an app is created. Changing to the "all" zip in the wrapper properties file did not work because this kept getting changed back to the "bin" zip.
This was solved when it was understood that the "gradle-wrapper.properties" file simply stores the values from the "wrapper" task, and if this task is run after the properties are changed, they get changed right back.
This is easily fixed by setting some properties on the wrapper task:
wrapper.gradleVersion='3.2.1'
wrapper.distributionType=Wrapper.DistributionType.ALL
Now importing the project into IDEA gives you smart editing of your build.gradle.
when I choose build.gradle in IDEA and open it, IDE prompts
You can configure Gradle wrapper to use distribution with sources. It will provide IDE with Gradle API/DSL documentation.
I choose Ok, apply suggestion!
after project refreshing I am able to use code completion
before you import your project, configure it to use the customizable gradle wrapper as per the instructions here :-
https://docs.gradle.org/current/userguide/gradle_wrapper.html
add a task to your top level project like this:-
task wrapper(type: Wrapper) {
println "Wrapper gradleVersion = '2.12'"
gradleVersion = '2.12'
}
or whatever the latest version is.
make sure you can build the project from the gradle command line before you try importing into intelliJ, using the ./gradlew command, which will download and install a gradle distribution for you the first time you build.
set your java home, intelliJ home and gradle home variables in your machine and in intelliJ (mine look like this, yours may be different depending on your setup and your history of hacking around your machine...:-
(from .bashrc
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
)
When you do import, choose the customisable gradle wrapper. if all is well, when you open the top level build.gradle for your project, you will be asked to configure sources for the gradle dsl, which will also update your gradle wrapper properties file to this:-
#Thu Mar 31 14:04:00 BST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-all.zip
.. the change being from ... bin.zip to all.zip. and that's it. This had been giving me lots of grief for a long time, but that's the way to do it. (on IntelliJ IDEA 2016.1 CE at least...)
most of this was in
Dimitry's answer too, but I couldn't get it to work using the default wrapper , it had to be the customisable wrapper.