Class GradleException

All Implemented Interfaces:
Serializable, org.gradle.internal.exceptions.ResolutionProvider
Direct Known Subclasses:
BuildCancelledException, CircularReferenceException, ConfigurationCycleException, org.gradle.internal.exceptions.DefaultMultiCauseException, DuplicateFileCopyingException, org.gradle.process.internal.ExecException, GradleScriptException, IllegalDependencyNotation, InvalidActionClosureException, InvalidModelException, InvalidModelRuleDeclarationException, InvalidModelRuleException, InvalidPluginException, InvalidUserCodeException, InvalidUserDataException, ManifestException, ModelInstantiationException, ModelRuleBindingException, PluginInstantiationException, PublishException, ReadOnlyModelViewException, ReportContainer.ImmutableViolationException, ResourceException, StopActionException, TaskInstantiationException, TestExecutionException, UnknownDomainObjectException, UnknownModelException, VerificationException, WriteOnlyModelViewException

@NullMarked public class GradleException extends RuntimeException implements org.gradle.internal.exceptions.ResolutionProvider
The base class of all exceptions thrown by Gradle.

Implements ResolutionProvider as of Gradle 9.9, to make it simple to provide a list of resolutions for any exception.

Deliberately calls super(X, Y, Z...) constructors instead of using a telescoping constructor pattern, since passing an explicit null cause counts as initializing it, which makes any later Throwable.initCause(Throwable) call throw IllegalStateException.

Resolutions are tracked as an internal, mutable list, so that nested catch blocks can provide and modify resolutions with additional context.

Since:
0.7
See Also:
  • Constructor Details

    • GradleException

      public GradleException()
      Creates a new GradleException.
      Since:
      0.7
    • GradleException

      public GradleException(String message)
      Creates a new GradleException.
      Since:
      0.7
    • GradleException

      public GradleException(String message, @Nullable Throwable cause)
      Creates a new GradleException.
      Since:
      0.7
    • GradleException

      @Incubating public GradleException(String message, @Nullable Throwable cause, Iterable<String> resolutions)
      Creates a new GradleException carrying the given resolution suggestions.

      There is deliberately no (String, Iterable) overload. It would make new GradleException(message, null) ambiguous with GradleException(String, Throwable): Java and Kotlin would reject such a call at compile time, and Groovy, which resolves overloads from the runtime types, would select the resolutions constructor and fail on the null. To attach resolutions without a cause, use GradleException(String) followed by addResolution(String).

      Note that passing a null cause here still counts as initializing it, so a later Throwable.initCause(Throwable) call on the result throws IllegalStateException.

      Since:
      9.9.0
  • Method Details

    • addResolution

      @Incubating public void addResolution(String resolution)
      Adds a potential resolution to this exception.
      Since:
      9.9.0
    • clearResolutions

      @Incubating public void clearResolutions()
      Clears the resolutions from this exception.
      Since:
      9.9.0
    • getResolutions

      @Incubating public List<String> getResolutions()
      Gets the resolutions.

      This is left non-final to allow DefaultMultiCauseException to override it.

      Specified by:
      getResolutions in interface org.gradle.internal.exceptions.ResolutionProvider
      Since:
      9.9.0