Reporting warnings

A warning reporter service was added to Grade in 8.6, but it was not really until 8.13 where this got finalised. As from Grolifant 5.4 there is an API to report warnings, and it will work across all supported versions. If the Gradle version < 8.11, the report will be output to a text file, but from 8.11 onwards it uses the actual Gradle reporting service under the hood.

The GrolifantProblemReporter API can be accessed via ConfigCacheSafeOperations or any task that derives from GrolifantDefaultTask.

import org.ysb33r.grolifant5.api.core.GrolifantProblemReporter
final problemReporter = ConfigurationsCacheSafeOperations(project).problemReporter()

problemReporter.report( 'id', 'display', 'grpId', 'grpDisplay') { (1)
    contextualLabel = 'label' (2)
    details = 'A description of the problem' (3)
    documentAt = 'https://gitlab.example/org/project/issue/13' (4)
    fileLocation = '/path/to/file' (5)
    lineInFileLocation( '/path/to/file', 13) (6)
    lineInFileLocation( '/path/to/file', 13, 55) (7)
    lineInFileLocation( '/path/to/file', 13, 55, 3) (8)
    offsetInFileLocation( '/path/to/file', 736, 125) (9)
    severity = 'advice' (10)
    severity = GrolifantProblemReporter.Severity.ADVICE (11)
    solution = 'Do not cur corners' (12)
    stackLocation() (13)
    withException( new GradleException('an example of an exception') ) (14)
}

problemReporter.report( 'id', 'display', GrolifantProblemReporter.ProblemGroup.of('grpId', 'grpDisplay')) { (15)
      // ... configure as above
}

problemReporter.report( (16)
    GrolifantProblemReporter.ProblemId.of(
        'id', 'display',
        GrolifantProblemReporter.ProblemGroup.of('grpIp', 'grpDisplay')
    )
) {
      // ... configure as above
}
1 Supply a problem id, a problem display name, a group id and a group display name, then configure the problem as per the next callouts.
2 Declares a short, but context-dependent message for this problem.
3 Declares a long description detailing the problem.
4 Declares where this problem is documented.
5 Declares that this problem is in a file.
6 Declares that this problem is in a file on a line.
7 Declares that this problem is in a file with on a line at a certain position.
8 Declares that this problem is in a file with on a line at a certain position and length.
9 Declares that this problem is in a file at a certain global position with a given length.
10 Declares the severity of the problem. One of advice, error or warning. The string is case-insensitive.
11 The severity can also be supplied as an instance of Severity.
12 Declares solutions and advice that contain context-sensitive data.
13 Add a stack trace. This is a NOOP on Gradle < 8.11.
14 Add an exception.
15 If you already have a fixed ProblemGroup created by the shown code snippet, use this method.
16 If you already have a fixed ProblemId and ProblemGroup created by the shown code snippets, use this method.

Output location

Problem reports are written to a text file at build/reports/problems/problems-report.txt for Gradle < 8.11 and build/reports/problems/problems-report.html for Gradle 8.12+.

Unsupported features

  • THe additionalData information block that is available from Gradle 13 and onwards is currently not supported. This should not be an issue in most cases.

  • The stackLocation is a NOOP on Gradle < 8.11.

  • The interfaces for raising exceptions are not supported. It might well be in future releases.