:samples-dir: /home/tcagent1/agent/work/64493a816be20d5a/promote-projects/gradle/build/git-checkout/platforms/documentation/docs/build/working/samples/install/problems-api-usage
:gradle-version: 8.7-rc-4

= Reporting and receiving problems via the Problems API Sample

[.download]
- link:zips/sample_problems_api_usage-groovy-dsl.zip[icon:download[] Groovy DSL]
- link:zips/sample_problems_api_usage-kotlin-dsl.zip[icon:download[] Kotlin DSL]

NOTE: You can open this sample inside an IDE using the https://www.jetbrains.com/help/idea/gradle.html#gradle_import_project_start[IntelliJ native importer] or https://projects.eclipse.org/projects/tools.buildship[Eclipse Buildship].

This sample shows how problems can be emitted via the Problems API and how those reports are consumed on the IDE-side.

## Running the sample

To run the sample, execute the `./gradlew :sample-ide:importBuild` command.

## Project structure

The sample consists of multiple, individual builds composed into a composite build with the following layout

* `sample-project`: A Gradle build with plugins that report problems
* `sample-ide`: a project that simulates the IDE functionality. In other words, it uses the Gradle Tooling API to configure and run the `sample-project` build and prints the received problem reports received during the process.
* `reporters/standard-plugin` shows the usage of the Problems API in a standard Gradle plugin.
* `reporters/model-builder-plugin` shows how to use the Problems API to report problems when reading project configuration via the Tooling API.
* `reporters/script-plugin` shows how to use the Problems API in a precompiled script plugin.


## Emitting a problem

Problems can be emitted via an injected `Problems` service.
Here's an example on how to report a problem from a plugin.

====
include::sample[dir="groovy",files="reporters/standard-plugin/src/main/java/reporters/StandardPlugin.java[tags=problems-api-report]"]
====


## Receiving a problem report

Problems are emitted as Tooling API progress events. They can be processed by registering a `ProgressListener`:

====
include::sample[dir="groovy",files="sample-ide/src/main/java/org/gradle/sample/SampleIde.java[tags=problems-tapi-event]"]
====


