|
| 1 | +# Шаблон Java-проекта для домашних заданий |
| 2 | + |
| 3 | +Шаблон для домашних заданий Академии Бэкенда 2025. |
| 4 | + |
| 5 | +## Структура проекта |
| 6 | + |
| 7 | +Это типовой Java-проект, который собирается с помощью инструмента автоматической |
| 8 | +сборки проектов [Apache Maven](https://maven.apache.org/). |
| 9 | + |
| 10 | +Проект состоит из следующих директорий и файлов: |
| 11 | + |
| 12 | +- [pom.xml](./pom.xml) – дескриптор сборки, используемый maven, или Project |
| 13 | + Object Model. В нем описаны зависимости проекта и шаги по его сборке |
| 14 | +- [src/](./src) – директория, которая содержит исходный код приложения и его |
| 15 | + тесты: |
| 16 | + - src/main – здесь находится код вашего приложения |
| 17 | + - src/test – здесь находятся тесты вашего приложения |
| 18 | +- [mvnw](./mvnw) и [mvnw.cmd](./mvnw.cmd) – скрипты maven wrapper для Unix и |
| 19 | + Windows, которые позволяют запускать команды maven без локальной установки |
| 20 | +- [pmd.xml](pmd.xml) и [spotbugs-excludes.xml](spotbugs-excludes.xml) – в проекте |
| 21 | +- используются [линтеры](https://en.wikipedia.org/wiki/Lint_%28software%29) для контроля |
| 22 | + качества кода. Указанные файлы содержат правила для используемых линтеров |
| 23 | +- [.mvn/](./.mvn) – служебная директория maven, содержащая конфигурационные |
| 24 | + параметры сборщика |
| 25 | +- [lombok.config](lombok.config) – конфигурационный файл |
| 26 | + [Lombok](https://projectlombok.org/), библиотеки помогающей избежать рутинного |
| 27 | + написания шаблонного кода |
| 28 | +- [.editorconfig](.editorconfig) – файл с описанием настроек форматирования кода |
| 29 | +- [.github/workflows/build.yml](.github/workflows/build.yaml) – файл с описанием |
| 30 | + шагов сборки проекта в среде Github |
| 31 | +- [.gitattributes](.gitattributes), [.gitignore](.gitignore) – служебные файлы |
| 32 | + для git, с описанием того, как обрабатывать различные файлы, и какие из них |
| 33 | + игнорировать |
| 34 | + |
| 35 | +## Начало работы |
| 36 | + |
| 37 | +Для того чтобы собрать проект, и проверить, что все работает корректно, можно |
| 38 | +запустить из модального окна IDEA |
| 39 | +[Run Anything](https://www.jetbrains.com/help/idea/running-anything.html) |
| 40 | +команду: |
| 41 | + |
| 42 | +```shell |
| 43 | +mvn clean verify |
| 44 | +``` |
| 45 | + |
| 46 | +Альтернативно можно в терминале из корня проекта выполнить следующие команды. |
| 47 | + |
| 48 | +Для Unix (Linux, macOS, Cygwin, WSL): |
| 49 | + |
| 50 | +```shell |
| 51 | +./mvnw clean verify |
| 52 | +``` |
| 53 | + |
| 54 | +Для Windows: |
| 55 | + |
| 56 | +```shell |
| 57 | +mvnw.cmd clean verify |
| 58 | +``` |
| 59 | + |
| 60 | +Для окончания сборки потребуется подождать какое-то время, пока maven скачает |
| 61 | +все необходимые зависимости, скомпилирует проект и прогонит базовый набор |
| 62 | +тестов. |
| 63 | + |
| 64 | +Если вы в процессе сборки получили ошибку: |
| 65 | + |
| 66 | +```shell |
| 67 | +Rule 0: org.apache.maven.enforcer.rules.version.RequireJavaVersion failed with message: |
| 68 | +JDK version must be at least 23 |
| 69 | +``` |
| 70 | + |
| 71 | +Значит, версия вашего JDK ниже 23. |
| 72 | + |
| 73 | +Если же получили ошибку: |
| 74 | + |
| 75 | +```shell |
| 76 | +Rule 1: org.apache.maven.enforcer.rules.version.RequireMavenVersion failed with message: |
| 77 | +Maven version should, at least, be 3.8.8 |
| 78 | +``` |
| 79 | + |
| 80 | +Значит, у вас используется версия maven ниже 3.8.8. Такого не должно произойти, |
| 81 | +если вы запускаете сборку из IDEA или через `mvnw`-скрипты. |
| 82 | + |
| 83 | +Далее будут перечислены другие полезные команды maven. |
| 84 | + |
| 85 | +Для автоматического форматирования кода используйте команду: |
| 86 | + |
| 87 | +```shell |
| 88 | +mvn spotless:apply |
| 89 | +``` |
| 90 | + |
| 91 | +Запуск только компиляции основных классов: |
| 92 | + |
| 93 | +```shell |
| 94 | +mvn compile |
| 95 | +``` |
| 96 | + |
| 97 | +Запуск тестов: |
| 98 | + |
| 99 | +```shell |
| 100 | +mvn test |
| 101 | +``` |
| 102 | + |
| 103 | +Запуск линтеров: |
| 104 | + |
| 105 | +```shell |
| 106 | +mvn clean compile -am spotless:check modernizer:modernizer spotbugs:check pmd:check pmd:cpd-check |
| 107 | +``` |
| 108 | + |
| 109 | +Вывод дерева зависимостей проекта (полезно при отладке транзитивных |
| 110 | +зависимостей): |
| 111 | + |
| 112 | +```shell |
| 113 | +mvn dependency:tree |
| 114 | +``` |
| 115 | + |
| 116 | +Вывод вспомогательной информации о любом плагине (вместо `compiler` можно |
| 117 | +подставить интересующий вас плагин): |
| 118 | + |
| 119 | +```shell |
| 120 | +mvn help:describe -Dplugin=compiler |
| 121 | +``` |
| 122 | + |
| 123 | +## Дополнительные материалы |
| 124 | + |
| 125 | +- Документация по maven: https://maven.apache.org/guides/index.html |
| 126 | +- Поиск зависимостей и их версий: https://central.sonatype.com/search |
| 127 | +- Документация по процессу автоматизированной сборки в среде github: |
| 128 | + https://docs.github.com/en/actions |
| 129 | +- Документация по git: https://git-scm.com/doc |
| 130 | +- Javadoc для Java 23: |
| 131 | + https://docs.oracle.com/en/java/javase/23/docs/api/index.html |
| 132 | + |
| 133 | +# Стандартная справка Spring |
| 134 | + |
| 135 | +# Getting Started |
| 136 | + |
| 137 | +### Reference Documentation |
| 138 | + |
| 139 | +For further reference, please consider the following sections: |
| 140 | + |
| 141 | +* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) |
| 142 | +* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/3.4.2/maven-plugin) |
| 143 | +* [Create an OCI image](https://docs.spring.io/spring-boot/3.4.2/maven-plugin/build-image.html) |
| 144 | +* [Distributed Tracing Reference Guide](https://docs.micrometer.io/tracing/reference/index.html) |
| 145 | +* [Getting Started with Distributed Tracing](https://docs.spring.io/spring-boot/3.4.2/reference/actuator/tracing.html) |
| 146 | +* [Spring Boot Testcontainers support](https://docs.spring.io/spring-boot/3.4.2/reference/testing/testcontainers.html#testing.testcontainers) |
| 147 | +* [Testcontainers Kafka Modules Reference Guide](https://java.testcontainers.org/modules/kafka/) |
| 148 | +* [Testcontainers Postgres Module Reference Guide](https://java.testcontainers.org/modules/databases/postgres/) |
| 149 | +* [Spring Boot Actuator](https://docs.spring.io/spring-boot/3.4.2/reference/actuator/index.html) |
| 150 | +* [Spring Configuration Processor](https://docs.spring.io/spring-boot/3.4.2/specification/configuration-metadata/annotation-processor.html) |
| 151 | +* [Spring Data JDBC](https://docs.spring.io/spring-boot/3.4.2/reference/data/sql.html#data.sql.jdbc) |
| 152 | +* [Spring Data JPA](https://docs.spring.io/spring-boot/3.4.2/reference/data/sql.html#data.sql.jpa-and-spring-data) |
| 153 | +* [Spring Data Redis (Access+Driver)](https://docs.spring.io/spring-boot/3.4.2/reference/data/nosql.html#data.nosql.redis) |
| 154 | +* [JDBC API](https://docs.spring.io/spring-boot/3.4.2/reference/data/sql.html) |
| 155 | +* [Spring for Apache Kafka](https://docs.spring.io/spring-boot/3.4.2/reference/messaging/kafka.html) |
| 156 | +* [Liquibase Migration](https://docs.spring.io/spring-boot/3.4.2/how-to/data-initialization.html#howto.data-initialization.migration-tool.liquibase) |
| 157 | +* [Prometheus](https://docs.spring.io/spring-boot/3.4.2/reference/actuator/metrics.html#actuator.metrics.export.prometheus) |
| 158 | +* [Testcontainers](https://java.testcontainers.org/) |
| 159 | +* [Validation](https://docs.spring.io/spring-boot/3.4.2/reference/io/validation.html) |
| 160 | +* [Spring Web](https://docs.spring.io/spring-boot/3.4.2/reference/web/servlet.html) |
| 161 | +* [Spring Reactive Web](https://docs.spring.io/spring-boot/3.4.2/reference/web/reactive.html) |
| 162 | + |
| 163 | +### Guides |
| 164 | + |
| 165 | +The following guides illustrate how to use some features concretely: |
| 166 | + |
| 167 | +* [Building a RESTful Web Service with Spring Boot Actuator](https://spring.io/guides/gs/actuator-service/) |
| 168 | +* [Using Spring Data JDBC](https://github.com/spring-projects/spring-data-examples/tree/master/jdbc/basics) |
| 169 | +* [Accessing Data with JPA](https://spring.io/guides/gs/accessing-data-jpa/) |
| 170 | +* [Messaging with Redis](https://spring.io/guides/gs/messaging-redis/) |
| 171 | +* [Accessing Relational Data using JDBC with Spring](https://spring.io/guides/gs/relational-data-access/) |
| 172 | +* [Managing Transactions](https://spring.io/guides/gs/managing-transactions/) |
| 173 | +* [Validation](https://spring.io/guides/gs/validating-form-input/) |
| 174 | +* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) |
| 175 | +* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) |
| 176 | +* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) |
| 177 | +* [Building a Reactive RESTful Web Service](https://spring.io/guides/gs/reactive-rest-service/) |
| 178 | + |
| 179 | +### Testcontainers support |
| 180 | + |
| 181 | +This project |
| 182 | +uses [Testcontainers at development time](https://docs.spring.io/spring-boot/3.4.2/reference/features/dev-services.html#features.dev-services.testcontainers). |
| 183 | + |
| 184 | +Testcontainers has been configured to use the following Docker images: |
| 185 | + |
| 186 | +* [`apache/kafka-native:3.8.1`](https://hub.docker.com/r/apache/kafka-native) |
| 187 | +* [`postgres:17-alpine`](https://hub.docker.com/_/postgres) |
| 188 | +* [`redis:7-alpine`](https://hub.docker.com/_/redis) |
| 189 | + |
| 190 | +Please review the tags of the used images and set them to the same as you're running in production. |
| 191 | + |
| 192 | +### Maven Parent overrides |
| 193 | + |
| 194 | +Due to Maven's design, elements are inherited from the parent POM to the project POM. |
| 195 | +While most of the inheritance is fine, it also inherits unwanted elements like `<license>` and `<developers>` from the |
| 196 | +parent. |
| 197 | +To prevent this, the project POM contains empty overrides for these elements. |
| 198 | +If you manually switch to a different parent and actually want the inheritance, you need to remove those overrides. |
0 commit comments