Intellij - No valid Maven installation found when configured to use Maven Wrapper - intellij-idea

I've upgraded my IntelliJ Community from 2021.1 to 2021.2 today and now I'm getting the following error when trying to run maven commands:
No valid Maven installation found. Either set the home directory in the configuration dialog or set the M2_HOME environment variable on your system.
But it's correctly configured to use Maven Wrapper:
My .mvn/wrapper/maven-wrapper.properties is as follow:
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
What am I supposed to do in order to keep using Maven Wrapper? Or is it a possible bug?

It is a bug: IDEA-258757 Cannot start tasks with maven wrapper
UPD: This is fixed in versions 2021.3+

Related

Intellij Plugin Development - Gradle does not find dependency of IntelliJ

I am currently developing a plugin for IntelliJ and trying to use another built-in IntelliJ Plugin as dependency (git4idea). As described in the IntelliJ Plugin Development documentation, I added the required JARs to my class Path in Project Structure:
Project Structure Dialog Screenshot
I also added <depends>Git4Idea</depends> to my plugin.xml file.
IntelliJ finds these jars now and Code Completion works well, no errors found...
But when I try to build the Plugin with gradle I get ClassNotFound errors or errors like this:
TkGitflowBaseImpl.java:15: error: package git4idea.commands does not exist
import git4idea.commands.Git;
^
Obviously, Gradle does not find these jars. Since they are part of the IntelliJ installation, I can't just add them to a lib folder and add them as local jars in the build.gradle file. As Gradle JVM, I chose the exact same JVM I chose as JVM behind the IDEA Platform SDK, so the jars should be available to Gradle.
Do you know how I can help Gradle find these jars or add them as "provided" dependencies without adding them to a lib folder?
I am using IntelliJ IDEA 2017.2.5 and Gradle 4.2.1
After reading through the documentation of the IntelliJ Gradle Plugin (https://github.com/JetBrains/gradle-intellij-plugin), I saw that that a "=" was missing in the build.gradle file like:
intellij {
version '2017.2.5'
pluginName 'pluginname'
plugins = ['Git4Idea']
}
instead of
intellij {
version '2017.2.5'
pluginName 'pluginname'
plugins ['Git4Idea']
}
https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html#optional-plugin-dependencies
build.gradle
intellij {
version = '2021.2'
plugins = ['Git4Idea']
}
src\main\resources\META-INF\plugin.xml
<depends>Git4Idea</depends>

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.

DeepLearning4j examples maven project unable to be processed by Intellij

As shown in the screenshot there is a dependency of the dl4j-0.4-examples project that is unable to be loaded by intellij.
Unable to get dependency information: Unable to read the metadata file
for artifact 'com.github.jai-imageio-core.jar': Invalid JDK version in
profile "java8-and-higher': Unbounded range [1.8
A similar problem resolved in this question
https://github.com/google/gson/issues/596
as quick fix open the pom file at your local repository and add ')'
and should looks like
91 [1.8,)
save and execute again
But in this case there is no jdk tag: so that approach can not be used.
Has anyone found a workaround to load this project into intellij?
The owners of the project have recognized this as an issue. If you would like to follow along here is the bug tracker:
https://github.com/deeplearning4j/dl4j-0.4-examples/issues/76
Update 2/28/16: The resolution: I needed to do
brew switch maven 3.3.9
There were multiple versions of maven installed on my machine but I did not know about brew switch. So some ways maven was working without doing the switch - but for this project a completely clean maven installation was required.

How to define Gradle's home in IDEA?

I am trying to import a Gradle project into IntelliJ, and when I get to the Gradle Home textbox, it is not automatically populated, nor will typing in the path of Gradle Home result in a valid location - I have the GRADLE_USER_HOME environment variable set (to what I think is!) the correct path, and I have been able to successfully import this same project into Eclipse. Any suggestions?
You can write a simple gradle script to print your GRADLE_HOME directory.
task getHomeDir {
doLast {
println gradle.gradleHomeDir
}
}
and name it build.gradle.
Then run it with:
gradle getHomeDir
If you installed with homebrew, use brew info gradle to find the base path (i.e. /usr/local/Cellar/gradle/1.10/), and just append libexec.
The same task in Kotlin in case you use build.gradle.kts:
tasks.register("getHomeDir") {
println("Gradle home dir: ${gradle.gradleHomeDir}")
}
Installed on a Mac via Homebrew, the path
/usr/local/opt/gradle/libexec
is preferable to
/usr/local/Cellar/gradle/X.X/libexec
since the former will survive version upgrades.
If you installed gradle with homebrew, then the path is:
/usr/local/Cellar/gradle/X.X/libexec
Where X.X is the version of gradle (currently 2.1)
If you are using IntelliJ, just do the following.
Close the project
(re)Open the project
you will see "Import gradle project" message on the right bottom. click.
select "Use default gradle wrapper". not "Use local gradle distribution"
That's all.
This is what helped me solve the problem of not having Gradle home set for the IDEA when importing a Gradle project.
THREE OPTIONS -- (A) Default Wrapper (B) "gradle 'wrapper' task configuration" OR (C) "local gradle distribution" defined by jetbrains: https://www.jetbrains.com/help/idea/gradle-settings.html
A. Default Wrapper (recommended)
If you are able, select this recommended option. If it is grayed out, see option C, which should then set your default for all subsequent projects.
B. Gradle 'Wrapper' Task Configuration
If you want IDEA to define your gradle version for you from your build script
Set this option if you define your gradle build versions as a task within your actual gradle build.
Example below from jetbrains: https://www.jetbrains.com/help/idea/gradle-settings.html
(useful if you do not want to share gradle builds between projects)
C. Local Gradle Distribution
1. Run the following command to get gradle location:
brew info gradle (if gradle was installed with homebrew)
2. You are looking for something like this:
/usr/local/Cellar/gradle/4.8.1
3. Next, append 'libexec' to the gradle location you just found:
/usr/local/Cellar/gradle/4.8.1/libexec
This is because "libexec is to be used by other daemons and system utilities executed by other programs" (i.e. IDEA). Please see https://unix.stackexchange.com/questions/312146/what-is-the-purpose-of-usr-libexec
4. Finally, put that new path in the Gradle home input box if IDEA prompts you.
IDEA should now have allowed you to hit OK
C:\Users\<_username>\.gradle\wrapper\dists\gradle-<_version>-all\<_number_random_maybe>\gradle-<_version>
\Android studio\gradle didn't worked for me.
And "Default gradle wrapper" wasn't configured while importing (cloning) the project from bitbucket
If it causes problem to figure out the path, here is my path :
C:\Users\prabs\.gradle\wrapper\dists\gradle-5.4.1-all\3221gyojl5jsh0helicew7rwx\gradle-5.4.1
This is instruction for MAC only.
I had the same problem. I solved it by configuring $GRADLE_HOME in .bash_profile. Here's how you do it:
Open .bash_profile (usually it's located in the user’s home directory).
Add the following lines to update $PATH variable:
export GRADLE_HOME=/usr/local/opt/gradle/libexec
export PATH=$GRADLE_HOME/bin:$PATH
Save it.
Apply your changes by running
source .bash_profile
I wrote my own article with instruction in a case if somebody will encounter the same problem.
On a mac it should ideally be at : /Applications/Android Studio.app/Contents/gradle/gradle-2.14.1
(Replace the version string with the latest)
AFAIK it is GRADLE_HOME not GRADLE_USER_HOME (see gradle installation http://www.gradle.org/installation).
On the other hand I played a bit with Gradle support in Idea 13 Cardea and I think the gradle home is not automatically discover by Idea. If so you can file a issue in youtrack.
Also, if you use gradle 1.6+ you can use the Graldle support for setting the build and wrapper. I think idea automatically discover the wrapper based gradle project.
$ gradle setupBuild --type java-library
$ gradle wrapper
Note: Supported library types: basic, maven, java
Regards
If you're using MacPorts, the path is
/opt/local/share/java/gradle
I had to setup the Project SDK before selecting gradle path. Once that was set correctly, I had to choose "Use default gradle wrapper (recommended) in "Import Project from Gradle" dialog.
Still works if I remove gradle using brew:
$ brew remove gradle
This is where my gradle home is (Arch Linux):
/usr/share/java/gradle/
I had some weird errors where it could not find my class, I had to right click on my src folder (was red) to "Make Directory as" -> Source Folder Root
Click New -> Project from existing sources -> Import gradle project...
Then Idea recognized gradle automatically.
I couldn't get it to accept my Gradle JVM selection until I deleted a broken JDK
Th window below is from File -> Other Settings -> Structure For New Projects...
I had a red 1.8 JDK SDK entry here, once I deleted that Gradle JVM error below disappeared and I could move on to the next step
In case you are using Mac, most probably your gradle home should be /usr/local/gradle-2.0 for example.
In preference of IDEA search for gradle and set gradle home as given above.
It should work

IntelliJ gives Fatal Error: Unable to find package java.lang in classpath or bootclasspath

When I try to make a simple module in IntelliJ it responds with:
Fatal Error: Unable to find package java.lang in classpath or bootclasspath
Somehow the JDK language jars were removed from the classpath. All I had to do was reapply the JSDK home path.
Goto:
File -> Project Structure -> Platform Settings -> SDKs
Re-apply the JSDK home path.
Doing this added about 15 jars to the classpath. Apparently these are important for compiling.
File -> Project Structure -> Platform Settings -> SDKs, remove existing SDK and add it again.
Works for me in IntelliJ 2017.3.
This error happend to me after i've updated my JDK version to jdk1.8.0_161 -
But the project's sdk was still pointing to the old jdk 1.8.0_131
(Seems that updgrading java causing the previous version to be wiped).
Do this:
In the IntelliJ IDE go to File > Project Structure, from there:
Within Platform Settings > SDKs:
Make sure that the JDK Home path field is pointing to a valid JDK folder (add a new entry if needed e.g. jdk1.8.0_161).
Within Project Settings > Modules:
Make sure that the Module SDK is set to the same entry you picked in the Platform Settings > SDKs
Save & Build again.
This worked for me:
In Preferences Build Tools > Maven > Runner > Environment Variables set JAVA_HOME to your JDK home path.
Usually you want to use the same Java JDK you are using in IntelliJ. You can find that under Project Structure > Platform Settings > SDKs under JDK home path.
e.g. /Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home
In Intellij Community 2019.1, this is what I did to solve the issue
Project Structure > Platform Settings > SDKs
Removed all existing SDKs listed ( I had multiple SDK listed there)
Add the required SDK only and Apply
File > Project Structure
JDK home path : PASTE_THE_JDK_LOCATION (Like here in the "Project Structure screen shot"
Build Again
Cheers :)
After following this answer,
I learned that %LOCALAPPDATA%/IDEA/config/options/jdk.table.xml contained incorrect entries. Fixing the JDK table fixed the problem.