Tiago Tiago - 1 year ago 108
Java Question

Gradle - How to set it up so it displays which file the error is?

More often than not gradle does not show in which class a certain error is.

For instance, I have a class

which uses my other class
. Therefore, A.java has the following import:

import my.package.Utils;

If I go to class
, delete the import above and clean the project, gradle gives me the following message:

Information:25/08/15 9:18 AM - Compilation completed with 1 error and 0 warnings in 22s 800ms
Error:Gradle: Execution failed for task ':app:compileBauDebugAspectj'.
> Utils cannot be resolved

The problem is that message does not say anywhere the problem is in class A. So the only way of me finding that out is by manually opening all classes that uses my Utils class until I find out the one in which the import is missing (in this case, A).

Is there a way to make gradle say exactly which class the error is? I can't believe it throws such generic errors without pinpointing where they are (especially in these basic cases like missing an import).

Answer Source

If you are using Android Studio, use Build > Rebuild Project, not Build > Clean Project.

Using Rebuild Project, or command-line Gradle builds, will happily point out the specific location of errors. For example, here is the output of a missing import from the Gradle Console in Android Studio 1.3.1:

Executing tasks: [clean, :app:compileDebugSources, :app:compileDebugAndroidTestSources]

Configuration on demand is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:preReleaseBuild UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
/home/mmurphy/stuff/CommonsWare/projects/andprojector/app/src/main/java/com/commonsware/andprojector/MainActivity.java:40: error: cannot find symbol
  symbol:   variable EventBus
  location: class MainActivity
/home/mmurphy/stuff/CommonsWare/projects/andprojector/app/src/main/java/com/commonsware/andprojector/MainActivity.java:45: error: cannot find symbol
  symbol:   variable EventBus
  location: class MainActivity
Note: /home/mmurphy/stuff/CommonsWare/projects/andprojector/app/src/main/java/com/commonsware/andprojector/MainActivity.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
2 errors


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.


Total time: 1.971 secs

You get equivalent output from running gradle assembleDebug at the command line.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download