I'm working on a Gradle plugin. Sometimes I want to look at the source code or Javadocs of Gradle's own classes. I want to do it from IntelliJ IDEA, without having to open a separate application. That is, Ctrl+click or Ctrl+B on a Gradle method or class and have IntelliJ open the source code of Gradle itself.
I have tried everything from Attaching Gradle sources in IntelliJ IDEA :
adding wrapper { ... } block in build.gradle
file gradle/wrapper/gradle-wrapper.properties has distribution type all (and, to my knowledge, has never had other distribution type on this particular machine)
I have also tried attaching sources manually by downloading Gradle source code from GitHub, but IntelliJ doesn't seem to be able to ingest it.
In addition to that, I have tried standard troubleshooting remedies of IntelliJ:
Refresh Gradle project
File > "Invalidate Caches / Restart" > "Invalidate and Restart"
Yet, when I click on method project.getProperties() (as an example), IntelliJ IDEA opens decompiled Project.class instead of the source code file Project.java.
How to make IntelliJ IDEA open Gradle's own source code?
Looks like you are facing this issue: IDEA-197970.
Related
I am trying to make use of modules and gradle subprojects and either receive compile time errors or complaints from IntelliJ.
My project structure is as follows:
Root
- settings.gradle
- core
- build.gradle
- desktop
- build.gradle
- src/main/java/module-info.java
The desktop build.gradle file as a requirement on core as:
dependencies {
implementation project(":core")
}
There is no reference to the "core" project in the module-info.java files.
In this configuration, IntelliJ doesn't like usage of classes from the "core" project in the "desktop" project (I see a lot of red), but running gradlew.bat desktop:run works with no issues. Bug with IntelliJ? I am using microsoft's openjdk, but hopefully that doesn't matter.
My best attempt to fix this, was to add a module-info.java file to the core project as well and reference the core project in the desktop project's module-info.java file. Unfortunately this configuration, while making IntelliJ happy, renders me unable to run the desktop from command line anymore. I get errors about the core project being unable to find required modules that are the exact same as the required modules I pull in for the desktop module. I think this might be an error on my part, but I'm not sure how or what to do to fix it.
Would appreciate any insight.
P.S. Of these issues, I think I would prefer to get IntelliJ working with the first setup, because I intend to have this core library be shared between the desktop project and an android project, and while I haven't looked into it yet, I am not sure Android supports new java modules?
I think terminal should be the first priority. If your original setup made it compiled successfully under terminal, then there is no problem in your project. Do not add extra files for just making the IDE happy.
There's still something you can do. The first step is compiling your project successfully under terminal. This step downloads all the necessary dependencies before IntelliJ, reducing the problem scope to IntelliJ's linking and indexing. Then there are some options:
In the Gradle tool window, click the top-left button Refresh all Gradle projects.
Delete all the .idea folders in your project. Then open the root folder of your project via UI or CLI.
Click the invalidate caches/restart in the main menu.
You can also also create a new Gradle multi-module project with command gradle init, and open it with IntelliJ. It should be analyzed by IntelliJ normally. Then you can compare its project structure with yours. Maybe there's something different.
Hope these steps could help you.
I ported our project to gradle.
Everything runs fine, also debug.
However, sometimes I'd like to start a specific main belonging to a given class, which is different from the mainClass specified in Gradle.
How can I achieve something like that without having to modify manually everytime build.gradle?
Right click -> Run still executes the gradle mainClass..
What version of NetBeans are you running?
NetBeans 11.3 (with built-in Gradle support, not the external plugin), runs the selected file when you use the context menu as described.
It appears to inject a "runSingle" task into the Gradle project to accomplish this.
I have a Gradle composite build project which contains a custom Gradle plugin. This project builds fine when using Gradle CLI, but IntelliJ fails.
I tried a few different variations on the plugin version within the resolutionStrategy block: org.test:test-plugin:0.0.1 and test-plugin:test-plugin.gradle.plugin:0.0.1 as described here: https://docs.gradle.org/current/userguide/plugins.html#sec:plugin_markers - both of those work from the CLI; changing to invalid values ("blah:blah") causes a failure.
I've made a sample Github project that contains the code to reproduce, here: https://github.com/mwmitchell/intellij-gradle-plugin-composite-build-bug along with instructions to reproduce and a workaround. The workaround is something that's not really feasible for me, as it requires repeating configuration code (dependencies, plugins etc.) and I have many, many projects that require the same/common configuration.
I would expect IntelliJ to load the project successfully, just like the CLI does. It seems like IntelliJ is loading the sub-project (:project-1:library-a) before the parent (:project-1), such that the java-library is not actually applied to the sub-project when it's evaluated.
Thanks for the sample project! Indeed, it is an issue in IntelliJ IDEA, see this ticket.
Gradle projects can have only one settings.gradle. You can include subproject "library-a" with include 'project-1:library-a' in the main settings.gradle.
I'm using IntelliJ 14.1.1 on Windows.
I have a project (mainly java) with a little web module, built with maven.
In my web module, I'd like to accomplish this scenario :
I edit a Javascript file located in the web module, folder resources/js
When IntelliJ automatically saves the file, I'd like it to be copied automatically to target/classes so that my web server detects the change and reload it automatically.
My goal is to have immedlate feedback : I edit a JS file, and then I have it available in my browser.
The only way I found is to go to "Maven Project", and assign a shortcut to the maven goal which compiles the module. But this takes too long, and it's far from the "Ctrl+S" of Eclipse (Eclipse auto build let me have this behavior).
I also tried to use the File Watcher option of IntelliJ, but it seems it can only parse less/css and I cannot make a simple copy of file/folder with it.
Any help would be welcome to achieve such an immediate feedback on typing in IntelliJ.
Thank you
All I want to do is use Android Studio without converting to Gradle. I MUST use maven (Client Requirements). How can I accomplish this?
I was able to get this working by opening up the pom.xml file but every time I close the project and reopen it, gradle is forced on me and I can't run anymore. Project layout also changes on me.
When I open up the project the first time using pom.xml, the module looks like this:
When I close the project and open up a 2nd time, the module looks like this:
(With the inability to run because Run/Debug says 'No Android facet found in the module')
I can get back to my original state by doing File->Open and reselecting the pom.xml file. I make sure to hit no on the first pop-up:
I blanked out my build.gradle file like so:
buildscript {
repositories {
}
dependencies {
}
}
repositories {
}
dependencies {
}
Extra Notes:
Exported from eclipse ADT for a build.gradle file. Android Studio was missing all External Libraries that were Maven
Dependencies.
Started my own build.gradle file to indlude dependencies but I don't want to maintain two separate files (build.gradle & pom.xml).
Deleted the build.gradle file and anything gradle related in the android project folder before reopening but that did nothing.
Developing on Linux OS Android Studio version 0.4.2
I don't like to answer my own questions but I thought a work around might help others in this case.
What I noticed is that Android Studio fights between gradle and maven and chooses gradle if you have a gradlefile for the project as well as maven.
Work Around
Open Module Settings
Remove all modules. Select the module and hit the minus key to
delete.
Click yes on the prompt.
Open up Maven Projects and click the plus key
Browse to your pom file and hit open.