### Configure Maven Local Repository Source: https://github.com/problem4j/problem4j-spring/blob/main/README.md Example of how to configure repositories in a target project to use artifacts from the local Maven repository. ```kotlin repositories { mavenLocal() mavenCentral() } ``` -------------------------------- ### Example Problem Response (application/problem+json) Source: https://github.com/problem4j/problem4j-spring/blob/main/README.md This JSON structure represents the problem response generated by the custom resolver for an invalid request. ```json { "type": "errors/invalid-request", "title": "Invalid Request", "status": 400, "detail": "bad input for user u-456", "userId": "u-456" } ``` -------------------------------- ### DCO Sign-off with GitHub Nickname Source: https://github.com/problem4j/problem4j-spring/blob/main/CONTRIBUTING.md An example of a DCO sign-off using a GitHub nickname and a noreply email address, useful for maintaining privacy. ```text Signed-off-by: nickname <12345678+nickname@users.noreply.github.com> ``` -------------------------------- ### Generate Problem response from custom exception with @ProblemMapping Source: https://github.com/problem4j/problem4j-spring/blob/main/README.md Annotate a custom exception with @ProblemMapping to automatically generate a Problem response. This example shows how to map exception fields and extensions. ```java @ProblemMapping( type = "errors/invalid-request", title = "Invalid Request", status = 400, detail = "{message}: {fieldName}", extensions = {"userId", "fieldName"}) public class ExampleException extends RuntimeException { private final String userId; private final String fieldName; public ExampleException(String userId, String fieldName) { super("bad input for user " + userId); this.userId = userId; this.fieldName = fieldName; } } ``` -------------------------------- ### Implement Custom ProblemResolver in Spring Source: https://github.com/problem4j/problem4j-spring/blob/main/README.md Implement the ProblemResolver interface to define custom logic for resolving exceptions into Problem objects. This example shows how to handle a specific ExampleException. ```java import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; import org.springframework.stereotype.Component; import io.github.problem4j.spring.ProblemResolver; import io.github.problem4j.spring.ProblemContext; import io.github.problem4j.core.Problem; @Component public class ExampleExceptionResolver implements ProblemResolver { @Override public Class getExceptionClass() { return ExampleException.class; } @Override public Problem resolve( ProblemContext context, Exception ex, HttpHeaders headers, HttpStatusCode status) { return Problem.builder() .type("errors/invalid-request") .title("Invalid Request") .status(400) .detail("bad input for user " + ((ExampleException) ex).getUserId()) .extension("userId", ((ExampleException) ex).getUserId()) .build(); } } ``` -------------------------------- ### Gradle Dependencies for Problem4J Spring Source: https://github.com/problem4j/problem4j-spring/blob/main/README.md Add the problem4j-spring library as a dependency to your Gradle project using the Kotlin DSL. Select the artifact corresponding to your Spring Boot setup (webflux or webmvc). Java 17 or higher is required. ```groovy dependencies { // pick the one for your project implementation("io.github.problem4j:problem4j-spring-webflux:${version}") implementation("io.github.problem4j:problem4j-spring-webmvc:${version}") } ``` -------------------------------- ### Build the Project with Gradle Source: https://github.com/problem4j/problem4j-spring/blob/main/README.md The simplest command to build the project, which includes compilation and running tests. ```bash ./gradlew ``` -------------------------------- ### Format Code with Gradle Source: https://github.com/problem4j/problem4j-spring/blob/main/README.md Apply code formatting rules defined in build.gradle.kts using the spotlessApply task. Building will fail if code is not properly formatted. ```bash ./gradlew spotlessApply ``` -------------------------------- ### Build and Validate Project Source: https://github.com/problem4j/problem4j-spring/blob/main/CLAUDE.md Run these Gradle commands to format code, build, and test the project. Always validate changes with a full build and test run. ```shell ./gradlew # default: spotlessApply build (preferred) ./gradlew spotlessApply # auto-format code ./gradlew build # compile + test + spotlessCheck ./gradlew test # tests only ``` -------------------------------- ### Execute Tests with Gradle Source: https://github.com/problem4j/problem4j-spring/blob/main/README.md Use the 'test' task to run all project tests. Tests do not alter the release version of the bytecode. ```bash ./gradlew test ``` -------------------------------- ### Format Code and Update License Year Source: https://github.com/problem4j/problem4j-spring/blob/main/README.md Use the spotlessApply task with the -Pspotless.license-year-enabled flag to update the year in license headers. This is important for publishing pipelines. ```bash ./gradlew spotlessApply -Pspotless.license-year-enabled ``` -------------------------------- ### Environment Variables for Publishing Source: https://github.com/problem4j/problem4j-spring/blob/main/RELEASING.md Set these environment variables in your CI/CD system for publishing artifacts. These include Sonatype credentials and PGP keys for signing. ```bash # generated tokens on Sonatype account, do not use real username/password PUBLISHING_USERNAME= PUBLISHING_PASSWORD= # generated PGP key for signing artifacts SIGNING_KEY= SIGNING_PASSWORD= ``` -------------------------------- ### Gradle Task for Publishing to Maven Central Source: https://github.com/problem4j/problem4j-spring/blob/main/RELEASING.md Use this Gradle task to publish artifacts to the Sonatype repository, which then allows them to be pushed to Maven Central. Ensure the version property is correctly set. ```bash ./gradlew -Pversion= -Psign publishAggregationToCentralPortal ``` -------------------------------- ### Publish to Local Maven Repository Source: https://github.com/problem4j/problem4j-spring/blob/main/README.md Use the publishToMavenLocal task to publish the built artifacts to your local Maven repository. ```bash ./gradlew publishToMavenLocal ``` -------------------------------- ### Gradle (Kotlin DSL) Dependency Management Source: https://github.com/problem4j/problem4j-spring/blob/main/problem4j-spring-bom/README.md Add the Problem4J Spring BOM to your Gradle build using the Kotlin DSL. This allows you to declare individual problem4j-* Spring modules without specifying their versions. ```kotlin dependencies { implementation(platform("io.github.problem4j:problem4j-spring-bom:{version}")) implementation("io.github.problem4j:problem4j-core") implementation("io.github.problem4j:problem4j-jackson2") implementation("io.github.problem4j:problem4j-jackson3") implementation("io.github.problem4j:problem4j-spring-web") implementation("io.github.problem4j:problem4j-spring-webmvc") implementation("io.github.problem4j:problem4j-spring-webflux") } ``` -------------------------------- ### Throw ProblemException with a Problem object Source: https://github.com/problem4j/problem4j-spring/blob/main/README.md Use this to throw a ProblemException with a manually constructed Problem object. The response will be in application/problem+json format. ```java throw new ProblemException(Problem.of("Invalid Request", 400, "not a valid json")); ``` -------------------------------- ### Add DCO Sign-off to Commit Message Source: https://github.com/problem4j/problem4j-spring/blob/main/CONTRIBUTING.md Append this line to your commit message to certify your contribution under the project's license. ```text Signed-off-by: Your Name ``` -------------------------------- ### Maven Dependency Management Source: https://github.com/problem4j/problem4j-spring/blob/main/problem4j-spring-bom/README.md Configure your Maven project to use the Problem4J Spring BOM. Add the BOM to dependencyManagement with an import scope, then declare modules without versions. ```xml io.github.problem4j problem4j-spring-bom {version} pom import io.github.problem4j problem4j-core io.github.problem4j problem4j-jackson2 io.github.problem4j problem4j-jackson3 io.github.problem4j problem4j-spring-web io.github.problem4j problem4j-spring-webmvc io.github.problem4j problem4j-spring-webflux ``` -------------------------------- ### Maven Dependencies for Problem4J Spring Source: https://github.com/problem4j/problem4j-spring/blob/main/README.md Add the problem4j-spring library as a dependency to your Maven project. Choose the appropriate artifact for your Spring Boot version (webflux or webmvc). Java 17 or higher is required. ```xml io.github.problem4j problem4j-spring-webflux ${version} io.github.problem4j problem4j-spring-webmvc ${version} ``` -------------------------------- ### 404 Not Found Problem Object Source: https://github.com/problem4j/problem4j-spring/blob/main/problem4j-spring-webmvc/README.md This JSON represents the standard Problem object returned for 404 Not Found errors in Spring WebMVC when using this module. ```json { "status": 404, "title": "Not Found" } ``` -------------------------------- ### Automatically Sign Git Commits Source: https://github.com/problem4j/problem4j-spring/blob/main/CONTRIBUTING.md Use this command to automatically add the DCO sign-off to your commit message if your Git user information is configured. ```bash git commit -s -m "message" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.