Running the gradle build inside IntelliJ IDEA works fine. If though I run it from the command line it fails giving an error on every single character of the src.
"Execution failed for task ':compileJava'."
I am guessing that it is not able to find the compiler which is odd because running javac from the same command line shows it is live and kicking.
This is one of those moments when I am truly stumped. Is this a bug? Does IDEA insert something to stop you using the command line with the same build script? Surely all the IDEA is doing is reaching out to the command line anyway?
Any help greatly appreciated thanks.
EDIT:
The error on the command line includes hundreds of this kind:
/***.java:89:
unclosed character literal '±', '§', '~', '`', '\'', ^
/***.java:94:
illegal start of type for (int x = 0; x < forbidden.length; x++) { ^
/***.java:94:
')' expected for (int x = 0; x < forbidden.length; x++) { ^
Literally every single line in a class file throws an error. Like I said, compiling using IDEA built in build process is fine as it using the Jet Gradle plugin. Also, on the command line the gradle clean task works fine too.
We can configure the settings for how IntelliJ IDEA syncs with Gradle by pressing the settings icon in the Gradle tool window, and selecting Auto-Reload Settings. We can set IntelliJ IDEA to automatically reload the project after "Any changes" in the build script files, so changes are automatically reloaded.
Sometimes due to any issue or after formatting of your pc. Some of the Gradle files may get deleted unexpectedly. So when you will start building your apps you will get to see an error in Android studio as 'Error running android: Gradle project sync failed.
Press Alt+Insert to open the Generate context menu. From the context menu, select Add dependency. In the Dependencies tool window, in the search field, start typing the name of your dependency. In the list of results select the one you need and click Add.
It might not be related but I had similar problems in Intellij today where Gradle command line was failing with many compilation failures but Intellij showed no problems. This happened after a considerable refactor of project module names. Naturally I assume the IDE was wrong as its a more complex thing than the command line. I found in two separate instances I needed slightly different approaches!!
Solution 1
The solution for me was in intellij Build->"Rebuild Project" followed by a "Refresh all Gradle projects" button which is the blue circular arrows button at top of the "Gradle" tool window (View->"Tool Windows"->Gradle)
Solution 2
In another instance I also had to first delete all of the intellij external libraries using Ctrl-Alt-Shift-S to open projects Strucutre window. Then under libraries delete them all. I then followed this up with a "Refresh all Gradle projects" as mentioned above
Im not entirely sure what the gradle refresh button is doing really. At the end of the day both steps are, because of, and a solution to, an extra layer of complexity imposed by the IDE. Rule: Always trust the command line and beat on your IDE when its not making sense.
I had this issue with the follow
.
├── build.gradle
├── hello-world
├── plugin
│ └── hello-world
└── settings.gradle
3 directories, 2 files
build.gradle
rootProject.name = "root-hello-world"
settings.gradle
include ':hello-world'
include ':plugin:hello-world'
by some motive intellij confuses :plugin:hello-world
with :hello-world
, in my case to solve it:
hello-world
module folderclear project folder
rm -r `find . -type d -name "build"`
rm `find -name "*.iml"`
rmdir `find . -type d -empty`
rm -r .gradle/ .idea/
import the project again
Not sure if set something like project.name = plugin-hello-world
in submodule works
Obs: as said on gradle line command the build always works, even when it fails on intellij
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With