Intellij IDEA not importing dependencies from #Grab in Groovy project - intellij-idea

I have a groovy script I am working on, which imports dependencies using the #Grab annotation. This script will run within IDEA, and from the command line. However, within the IDE, the imports are shown in red (as unresolvable), and no auto-completion on the classes so imported is given.
I am accessing a corporate repository via a proxy, which has been configured as the Http Proxy within IDEA (the module should be, and is, in my local .m2 repo anyway!)
Anyone got any ideas (no pun intended!)?
I am using IntelliJ IDEA 12.5 Ultimate (IU-129.1135), JRE 1.7, and Groovy 2.1.6

As stated by CrazyCoder, Alt + Enter then select Grab the artifacts and Enter

There could be 2 problems interfering with the resolution of the Grab dependencies
Your source code folder has not been marked as "Sources Root". To do that, right click on the folder and select "Mark Directory As" -> "Sources Root"
Your project does not have a valid Project JDK. To do this, hit Ctrl-Alt-Shift-S, select "Project" -> "Project SDK" and give it a Java JDK.
Once these steps are done, you should be able to hit Alt + Enter and then select "Grab the artifacts"

Related

IntelliJ shows decompiled .class file instead of source code

I am having issues with IntelliJ - it shows me a "decompiled" version of the class instead of its source code if I ctrl+click the class.
This is what I see:
I am trying to open regular JDK source files.
The most relevant issue I found is explained here: Java sources replaced by decompiled files in Intellij
The most detailed answer I've found so far is there as well.
Yet it doesn't work for me:
Bytecode Viewer plugin is off.
Java Bytecode Decompiler plugin is off.
Platform, Project and Module all have same JDK version setup.
I have two JDKs available in IntelliJ: jdk1.8.0_161 and jbsdk8u112b287.2_windows_x86 (bundled with IntelliJ, but comes without src.zip). Tried with both (had to specify src.zip of jdk1.8.0_161 for jbsdk8u112b287.2_windows_x86) - no luck
src.zip is not corrupt - I can open it via WinRAR
When added jdk1.8.0_161 to IntelliJ, it automatically found src.zip. When manually adding src.zip to jbsdk8u112b287.2_windows_x86 Sourcepath tab - it started "Scanning for roots", but warned me that it "cannot determine what kind of files the chosen items contain" and offered me to "attach them as 'Sources'" so I agreed.
Tried File > Invalidate Caches / Restart... - same result.
Same issue in 2017.3 and fresh 2018.1 versions of IntelliJ.
Providing path for Documentation makes IntelliJ look for the documentation in the path specified. So it works as it should for both of JDKs. But not for sources.
Everything else works/compiles properly.
My settings:
1. Get the source files
Make sure you have downloaded and installed the source files of the JDK.
I'm on Arch Linux and installed them with pacman -S openjdk8-src which put a src.zip into /usr/lib/jvm/java-8-openjdk/. We'll use that zip file in the next step.
To list source packages of different JDK versions, do pacman -Ss "openjdk.*-src".
See this question on how to get the source files for your specific platform.
2. Point IntelliJ to the source files
In your module settings (open them with F4) under "Platform Settings" → "SDKs" → "Sourcepath", add the zip file containing the JDK source to your project JDK (be sure to pick the right JDK if IntelliJ lists more than one JDK) using the button with the plus sign:
3. Jump into the source
Select a JDK class, like Comparator, using IntelliJ's Search Everywhere or Ctrl+b with the cursor on the name of the class.
I also have the same problem. The problem for my case is that Project SDK is set to 13 [Invalid]. After I can Project SDK to a valid SDK. My problem is solved.
I tried all the things mentioned at other places for this but at the end I was doing a silly mistake. Intellij was pointing to JDK 11 for which there was no source code (I had both the SDKs 8 & 11). I removed JDK 11 and pointed to JDK 8. JDK had the source code, thus now I can see the source code on ctrl click. Also, I had disabled the bytecode viewer and decompiler plugins. Hope this helps some one.
This also happens for large files - IDEA decides to decompile them instead if indexing sources, which can take ages.
If you're willing to accept the drawdown, adding the following in Help | Edit Custom Properties might fix the problem:
idea.max.intellisense.filesize=4096
On ubuntu there was java version “OpenJDK” when I changed to “Oracle Java”, the error went away and javadoc returned
I meet same problem and finally it gone after I copy JDK to another folder and change config in IntelliJ. I think maybe cause there is a space in path before, because it is installed under "Program Files" folder.
For downloading the source code of class files belong to jar you can use download source option present on top right corner in the de-compiled class file.
On my Windows 10, expand maven:
For me going to File -> Project Structure -> Project -> SDK -> Add SDK -> Download JDK and selecting Oracle OpenJDK solved the problem. Prior to that I had a different JDK selected and apparently it didn't include source code
If you are in a maven project make sure in the project structure all the complied folders are in the excluded section.
I suggest to use Linux Instead of windows. It's easy to find and download Java.
If you are using Linux, you can download SDKMAN
Install Java by SDKMAN
# find version
$ sdk list java
# download
$ sdk install java x.y.z-amzn
ctrl+alt+shift+s add JDK
Switch project JDK
If you are using maven , Right click on Project explorer -> choose Maven -> chick on "reload projects"
This did the trick for me:
Make sure you select the option "Project Files" (instead e.g. "Project").

intelij always returns 404 for find jar on web

I always get an 404 error in intelij ide when I try to "find jar on web". The following appears:
And I can't find a way to change the urls intelij is using. I don't use a proxy.
How to configure this to make it work?
As described here, you may open the Project structure (⌘+; on mac or Ctrl+Shift+Alt+S on windows). Go to Libraries pane on the left and click on the + button and choose "From Maven..."
Provide the correct Maven URL for the jar that you need in the resulting dialog.
Screenshot from Intellij 15.0.1:

Play Framework 2.4 and IntelliJ Idea

I am trying to open a play 2.4 project in IntelliJ but since things have changed I don't know how to do this.
In previous versions I could just run
activator idea
Or use the activator UI and click on generate intelliJ project, but in 2.4 the idea command doesn't seem to exist
[error] Not a valid command: idea (similar: eval, alias)
[error] Not a valid project ID: idea
[error] Expected ':' (if selecting a configuration)
[error] Not a valid key: idea (similar: clean)
[error] idea
[error] ^
And the UI seems broken, when I click on generate intelliJ project it tries to compile the app and gives this error:
play/Play$
java.lang.NoClassDefFoundError: play/Play$
Use 'last' for the full log.
Failed to load project.
I created the project from scratch using the play java template with:
activator new
I have also tried importing the folder as a project but intelliJ doesn't seem to identify it as a project
I run into the same problem, as I used IDEA to open a project folder, it had an play 2 app in a sub folder, then I import module (play 2 app) to the system.
And it works well.
After that I have changed the module folder name, then when I run the app, it displayed:
Not a valid project ID: "project team"
I re-checked the folder, and found that in the File -> Project Structure option, the name of module is "root", and the "team" is the module for whole project (not the module imported by SBT), so apparently, the module wasn't functional after I changed the module folder name.
So I found and removed all .idea folder, which is IDEA configureation, then re-open/re-import the module, still not work. I thought it's IDEA cache issue, it do have cache for the opened project, so I changed the project folder from team to something else, clean the .idea folders, and re-open/re-import it. It worked.
If the play app is in the project folder as a sub folder, to import the module at File -> Project Structure.
The project name should be "root" when running it in IDEA. So in this case, you should rename "project team" to "root" in the name field.
Solution 1
In my case (IDEA 2018.2), I changed the lazy val variable in build.sbt, it had the name "root" when my project name was "top", changed "root" to "top".
Before:
lazy val root = (project in file(".")).enablePlugins(PlayScala)
After:
lazy val top = (project in file(".")).enablePlugins(PlayScala)
Change project variable
Solution 2
The method proposed by Tom solved my problem partially, because after rebooting the IDEA I returned the project name back, it was necessary to change the variable from "top" to "root" in build.sbt.
Before:
name: = "top"
After:
name := "root"
Intellij IDEA lets you quickly create a Play application without using a command prompt. You don’t need to configure anything outside of the IDE, the SBT build tool takes care of downloading appropriate libraries, resolving dependencies and building the project.
Before you start creating a Play application in IntelliJ IDEA, make sure that the latest Scala Plugin is installed and enabled in IntelliJ IDEA. Even if you don’t develop in Scala, it will help with the template engine and also resolving dependencies.
Basically, install Play Framework, Scala plugins and import project into Intellij as SBT project. Don't use activator to create IDEA project files. More details here.
It seems I had not updated scala/sbt to the latest version in intelliJ
Once I had done this it noticed that it was a valid project, though the docs don't seem to mention you can import it as an SBT project, just how to create it as a new sbt project (which I did not want to do as I wanted to create it via activator)
I also had the project/play-fork-run.sbt file issue
I use Intellij Idea 16.3.3 and this problem appears sometimes. How I fixed it? You just need to open your SBT plugin and under your project get the context menu then you should choose "Ignore SBT project". After a current process is finished you should turn on this option again. This is work for me:)

intelliJ 12 - cannot find the xml file i want it to

I want to get, when i press the little green "run me" button in intelliJ, the running program to pick up and use this file (in the project structure)
/src/config/some_folder/some_xml.xml
However, when i press that green run button, intelliJ 12 is giving me this error:
Resource not found on classpath using context ClassLoader: some_folder/some_xml.xml
In an attempt to resolve, this, I have this in my Settings:Compiler: Resource patterns
!?*.java;!?*.form;!?*.class;!?*.groovy;!?*.scala;!?*.flex;!?*.kt;!?*.cl;?*.xml;?*.config
note the penultimate xml entry.
I also unchecked the "use external build" button. I do not know what it means or does, but I read somewhere that it should not be used.
I also have these (among other entries) in Project Structure:Modules: Sources tab
config
config\some_folder
Marked in blue (sources) under the Source Folders heading.
There is no fancy pom.xml for this project - it is an old legacy project. If i add a pom.xml to resolve this, where would i put it, what would i put in it (in entirety) and would i need to tell intelliJ i now have a pom.xml?
EDIT ok, so intelliJ can find the file when i refer to it as
./config/some_folder/some_xml.xml
but will not find it if it is reffered to as
some_folder/some_xml.xml
I think this is the real issue - how do i resolve this?
src/config needs to be configured in the project as a resources folder. In the project tray, right click /src/config and select "Mark Directory As" -> "Source Root"

In Intellij, right click on a test does not present a "Run" option

In IntelliJ when I right click on a test I dont see a "Run ClassX or MethodY" anymore. In fact there is no "run" window and when I right click I cannot run any class.
It was all working fine about 3 hours ago so I am not quite sure what has changed.
IntelliJ 10.5.1 (Licensed and NOT community edition)
Java 1.6.0_24
This happens for all projects.
Update 1
I installed IDEA 11 and imported settings from 10 and then saw that it was not a free upgrade close IDEA 11 and started using IDEA 10. I am fairly certain things stopped working from that point but not sure. Is that a problem? Can I somehow delete IntelliJ configuration directory somehow and restart?
Adding a screenshot when I don't get Run option on right click:
My problem was that my test class wasn't public. I needed:
public class MyTest {
#Test
public void testMethod() {
instead of:
class MyTest {
#Test
void testMethod() {
If your project is a maven project then you can just right-click on the pom.xml file and select "add as Maven project".
This approach worked for me. (green plus third from the bottom)
I had the same problem. To fix it, I had to ensure that my class had a proper main method:
public static void main(String[] args) {
}
Every keyword in the above statement is critical. If you omit one, IntelliJ wont' recognize it. Easy-to-forget keywords are static, void, and the String[] args argument.
I had forgotten the arguments in mine ;-)
Also make sure your source code is inside a src folder which is marked as such by IntelliJ.
In my case, the cause was disabled JUnit plugin. (File — Settings — Plugins — JUnit, check, OK)
If you're using JUnit 5 (Jupiter), this happens when you use the old #Test annotation from JUnit 4. Just replace
import org.junit.Test;
with
import org.junit.jupiter.api.Test;
and IntelliJ should show the "Run" button again.
Ok after tremendous amount of eyeballing I located a {HOME}/.java directory which seemed to contain some Jetbrains related preferences. I deleted that directory plus {HOME}/.IntelliJ* directories. Then deleted all my intellij installations and downloaded it again from scratch and it now works fine..
Sigh....
Disabling gradle plugin solved the issue for me (community edition 2018.2)
In my case i right clicked the src folder and went to -> mark directory as -> sources root.
I had the same problem. I solve it by
File -> Invalidate Caches / Restart
right click on the top pom.xml -> Maven -> reimport
There should be no need to delete any configuration files.
I found that I used to have the Run option in the context menu to select either run tests or run Scala tests, etc. After I had selected an option for the first time, my options were no longer there.
I was able to resolve this issue and select the type of tests I wanted for that folder by creating a Run/Debug configuration following the instructions found in the documentation here...
https://www.jetbrains.com/help/idea/2016.1/creating-run-debug-configuration-for-tests.html?origin=old_help
As i had the same issue , i could clearly See that #Test is not providing any hint when i press control key and hover , and the same was confirmed as External Libraries was not having Gradle Dependencies added so i had to update the project as gradle project suggested by a pop up when you start Intellij.
I could resolve the issue by disabling the Gradle plugin from the Plugin menu and restart.
If the project is already added as a Maven one, unlink it.
right click on the project -> Maven -> Unlink Maven Projects
Then link it again:
right click on pom.xml -> + Add as Maven Project
I've just had the same problem and solved it in the following way.
Go to your $USER/$INTELLIJ directory e.g. $USER/.IdeaC2018.3 then find config/plugins. Rename the plugins directory and restart IntelliJ.
My guess is that the problem was caused when I upgraded IntelliJ and incompatibilities with the cucumber plugin.
For me this happened after updating Idea, and then updating all Plugins. Apparently Idea had not restarted yet. Going to File -> Settings -> Plugins and clicking 'Restart Idea' solved the problem
if you can see the play button in left side of the main function then click right click and press run.
in my case, I did not have an output folder.
file -> project structure -> under 'project' tab there's 'Project compiler output' -> define your folder.
Unfortunately, none of these worked for me. I had to
'File' -> "Invalidate Caches / Restart"
Click on pom.xml file, and then 'maven' -> "Generate Sources"
Search for pom.xml file --> Right Click on pom.xml --> Click on Add as Maven Project.
You should get a pop-up, saying downloading Mavin Plugin.
Wait till it gets completed. It takes some time depending on the number of content in pom.xml.
In the below screenshot, "BackendApp.java" is Driver Java file that contains
public static void main(String[] args){}
Right Click on such driver java file and you see Run option in green color.
I had this problem with a Kotlin project. Following action solved it:
right click on test folder -> select Mark Directory as -> choose Test Sources Root
So I had this problem on pycharm and the problem was that there was already a run configuration (in the dropdown next to the play button) that had the name of the file. When i deleted that run configuration it would create a new one that was correct.
I had the same problem and I tried all the above solutions nothing worked for me but after I install TestNG plugin it's started working since there are some TestNG annotations used in my unit tests
I had the same problem on my Intellij 2019.3 after that I updated from 2019.2.4. I thought that the problem came from the updated first, but the rollback didn't fix, so I tried de solution above e the problem was fixed. After configuring all my projects from scratch the problem get back, so I started to check everything I did. I discovered that an old project from Eclipse that uses files .launch to run and need some plugins to be able to execute on Intellij was causing the problem, after disable the following plugins the test option return.
In my case, my project is using Bazel.
The solution was to sync Bazel from Bazel plugin.
Since this is a top Google result when trying to figure out how to run a Scala project, and since for some reason IntelliJ (I'm on 2020.1.2) doesn't automatically create a run configuration for a Scala project (in contrary to a Java project), it's worth laying out the basics for future readers:
Click on "Edit Configuration" on the top right of the screen.
Inside the opened window, click the + button its top left.
Choose "Application".
Now, let's go through the required fields:
in the "Name" field, enter a name for this configuration, e.g. "run".
in the "Main Class" field, enter your main class name.
Alternatively, use the ... button to the left: inside the window that opens, click the "Project" tab, navigate to your main class, pick it and click "ok".
Note: If your main class doesn't have a main method, IntelliJ would show an alert. see listing 9 below.
Make sure the value in "Working Directory" field is correct (it should be the project folder).
in "Use classpath of module", select your module (see project vs module in IntelliJ)
That's it for configuring. Click "Apply", and close the window. Here's an example final result:
Note that my Main class is part of a package named Demo, but having a package is not necessary.
Inside the main class, make sure there's a main method.
See #Josiah Yoder answer for java, and for Scala it's:
def main(args: Array[String]): Unit = {
}
That's it. You should now have the green run and debug buttons enabled.
Seems there are version conflicts between plugins and IDEA itself that commonly break this functionality. Many of the solution here indicate people manually trying to identify the plug in, I found that to be impossible. So here is a generic way, without having to uninstall IDEA as one solution proposed:
File > Settings > Plugins > gear icon > disable all downloaded plugins
This fixed it for me.
Make sure the method is not static! JUnit only allows #Test before instance methods but Intellij doesn't complain even if you use #Test above a static method.