diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e4c951700..2bc4e6042 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,7 +17,107 @@ in the root directory of the repository. All contributions are subject to the [Developer Certificate of Origin (DCO)](https://developercertificate.org/). The DCO text is also included verbatim in the [dco.txt](dco.txt) file in the root directory of the repository. -## Getting Started +## Finding something to contribute + +Our [JIRA instance](https://hibernate.atlassian.net/browse/HV) is where all tasks are reported and tracked. + +In particular there is a [list of issues suitable for new contributors](https://hibernate.atlassian.net/issues/?filter=21199). + +## Create a test case + +If you have opened a JIRA issue but are not comfortable enough to contribute code directly, creating a self +contained test case is a good first step towards contributing. + +As part of our efforts to simplify access to new contributors, we provide [test case templates for the Hibernate family +projects](https://github.com/hibernate/hibernate-test-case-templates). + +Just fork this repository, build your test case and attach it as an archive to a JIRA issue. + +## Setting up a development environment + +### Build tools + +You will need JDK 21 or above for the build. + +A maven wrapper script is provided at the root of the repository (`./mvnw`), +so you can use that and don't need to care about the required version of Maven +(it will be downloaded automatically). + +### Develocity build cache and build scans + +Hibernate Validator relies on a [Develocity](https://gradle.com/develocity/) instance +at [https://ge.hibernate.org](https://ge.hibernate.org/scans?search.rootProjectNames=Hibernate%20Validator) +to speed up its build through a build cache and provide better reports. + +By default, only [continuous integration](#ci) builds will write to the remote build cache or publish build scans. + +Local builds of Hibernate Validator will: + +* write to a local build cache; +* read from both a local and a remote build cache to speed up builds; +* not write to the remote build cache; +* not publish any build scans. + +To opt out from build caches for a particular build (e.g. to debug flaky tests), +pass `-Dno-build-cache` to Maven. + +To publish build scans for your local builds, +[reach out to the team](https://hibernate.org/community/#contribute) to set up an account, +and once you have one, run this from the root of your local clone of Hibernate Validator: + +```shell +./mvnw com.gradle:develocity-maven-extension:provision-access-key +``` + +To opt out from build scans for a particular build (e.g. when working on a security vulnerability), +pass `-Dscan=false` to Maven. + +### IDE + +#### IntelliJ IDEA + +**WARNING**: Avoid running `./mvnw` while IntelliJ IDEA is importing/building, +and ideally avoid using Maven from the command line at all while IntelliJ IDEA is open. +IntelliJ IDEA's own build might conflict with the Maven build, leaving your working directory in an undetermined state +(some classes being generated twice, ...). +If you already did that, close IntelliJ IDEA, run `./mvnw clean`, and open IntelliJ IDEA again. + +You will need to change some settings: + +* `Build, Execution, Deployment > Build Tools > Maven`: set `Maven home path` to `Use Maven wrapper` +* In `Project structure`, make sure the project JDK is JDK 21. +* Set up [formatting rules and code style](#setup-ide-formatting). + +Then a few steps will initialize your workspace: + +* In the "Maven" side panel, click "Reload all Maven projects". +* To check your setup, click `Build > Rebuild Project`. + If the build has no errors, your workspace is correctly set up. +* If you encounter any problem, that might be caused by the project being half-built before you started. + Try again from a clean state: close IntelliJ IDEA, run `./mvnw clean`, open IntelliJ IDEA again, + and go back to the first step. + +#### Eclipse + +Eclipse shouldn't require any particular setup besides +[formatting rules and code style](#setup-ide-formatting). + +#### Formatting rules and style conventions + +Hibernate Validator has a strictly enforced code style. Code formatting is done by the Eclipse code formatter, +using the config files found in the `build/build-config/src/main/resources` directory. +By default, when you run `mvn install`, the code will be formatted automatically. +When submitting a pull request the CI build will fail if running the formatter results in any code changes, +so it is recommended that you always run a full Maven build before submitting a pull request. + +The [Adapter for Eclipse Code Formatter](https://plugins.jetbrains.com/plugin/6546-adapter-for-eclipse-code-formatter) plugin +can be used by IntelliJ IDEA users to apply formatting while within the IDE. Additionally, contributors might need to +increase import counts to prevent star imports, as this setting is not exportable and star imports will lead to +a build failure. + +## Contributing code + +### Prerequisites If you are just getting started with Git, GitHub and/or contributing to Hibernate Validator there are a few prerequisite steps: @@ -25,23 +125,26 @@ few prerequisite steps: * Make sure you have a [Hibernate JIRA account](https://hibernate.atlassian.net) * Make sure you have a [GitHub account](https://github.com/signup/free) * [Fork](https://help.github.com/articles/fork-a-repo/) the Hibernate Validator [repository](https://github.com/hibernate/hibernate-validator). -As discussed in the linked page, this also includes: - * [Setting](https://help.github.com/articles/set-up-git/) up your local git install - * Cloning your fork + As discussed in the linked page, this also includes: + * [Setting](https://help.github.com/articles/set-up-git/) up your local git install + * Cloning your fork * Instruct git to ignore certain commits when using `git blame`: ``` git config blame.ignoreRevsFile .git-blame-ignore-revs ``` -## Create a test case +### Development environment -If you have opened a JIRA issue but are not comfortable enough to contribute code directly, creating a self -contained test case is a good first step towards contributing. +Make sure to [set up your development environment](#setup) correctly. -As part of our efforts to simplify access to new contributors, we provide [test case templates for the Hibernate family -projects](https://github.com/hibernate/hibernate-test-case-templates). +Be especially careful about setting up the [formatting rules and code style](#setup-ide-formatting). + +If you built the project at least once (`./mvnw clean install`), +you can very quickly check that you have respected the formatting rules by running Checkstyle: +```bash +./mvnw spotless:check checkstyle:check -fn +``` -Just fork this repository, build your test case and attach it as an archive to a JIRA issue. ## Create a topic branch @@ -86,6 +189,15 @@ The project comes with formatting files located in: These files can be used in the IDE if applying formatting as-you-code within the IDE is something you'd prefer. +### Javadoc +Additionally, keep in mind the following Javadoc conventions, when working on the Hibernate Validator code base: + +* Use `{@code}` instead of ``, because it is more readable and `{@code}` also escapes meta characters +* `@param`, `@return` and `@throw` don’t end with a `.`; the first word starts with a lower-case letter +* If referring to other classes and methods of the library, use `{@link}` +* `{@link}` might be use for external classes, `{@code}` is accepted, too +* Use `