Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle build works fine in Intellij but EXACTLY the same build script fails with 100+ errors on the command line

Tags:

gradle

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.

like image 594
sectornitad Avatar asked Jun 13 '13 21:06

sectornitad


People also ask

How do I fix Gradle sync issues in IntelliJ?

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.

Why is Gradle build failing?

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.

How do I resolve Gradle dependencies in IntelliJ?

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.


2 Answers

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.

like image 76
Rob McFeely Avatar answered Oct 03 '22 13:10

Rob McFeely


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:

  • rename hello-world module folder
  • close intellij project
  • clear 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

like image 42
deFreitas Avatar answered Oct 03 '22 12:10

deFreitas