{"id":26538599,"url":"https://github.com/thorlauridsen/spring-boot-java-sample","last_synced_at":"2026-04-11T06:02:33.530Z","repository":{"id":283087247,"uuid":"950209080","full_name":"thorlauridsen/spring-boot-java-sample","owner":"thorlauridsen","description":"Spring Boot Java multi-project Gradle build sample using Spring Data JPA ","archived":false,"fork":false,"pushed_at":"2025-06-18T16:55:18.000Z","size":169,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-18T17:45:14.559Z","etag":null,"topics":["docker-compose","gradle","h2-database","jackson","java","liquibase","rest","rest-api","restful-api","spring","spring-boot","springboot","springdoc","swagger"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thorlauridsen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-03-17T19:57:20.000Z","updated_at":"2025-06-18T16:55:20.000Z","dependencies_parsed_at":"2025-03-18T14:30:34.860Z","dependency_job_id":"ac1c7e69-bab3-47d5-bdb0-b83c4f5797e0","html_url":"https://github.com/thorlauridsen/spring-boot-java-sample","commit_stats":null,"previous_names":["thorlauridsen/spring-boot-java-sample"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/thorlauridsen/spring-boot-java-sample","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thorlauridsen%2Fspring-boot-java-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thorlauridsen%2Fspring-boot-java-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thorlauridsen%2Fspring-boot-java-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thorlauridsen%2Fspring-boot-java-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thorlauridsen","download_url":"https://codeload.github.com/thorlauridsen/spring-boot-java-sample/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thorlauridsen%2Fspring-boot-java-sample/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260807106,"owners_count":23066086,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker-compose","gradle","h2-database","jackson","java","liquibase","rest","rest-api","restful-api","spring","spring-boot","springboot","springdoc","swagger"],"created_at":"2025-03-21T23:18:51.344Z","updated_at":"2025-12-30T22:30:04.156Z","avatar_url":"https://github.com/thorlauridsen.png","language":"Java","readme":"# Spring Boot Java sample project\n\nThis is a sample project for how you can set up a\n[multi-project Gradle build](https://docs.gradle.org/current/userguide/multi_project_builds.html)\nusing [Spring Boot](https://github.com/spring-projects/spring-boot)\nand [Java](https://www.java.com).\nYou can copy or fork this project to quickly set up a\nnew project with the same multi-project Gradle structure.\n\nThis project consists of a runnable REST API using Spring Boot Web MVC.\n\n## Usage\nClone the project to your local machine, go to the root directory and use:\n```\n./gradlew api:bootRun\n```\nThis will start the project using an in-memory H2 database.\n\n### Docker Compose\nTo run the project with [Docker Compose](https://docs.docker.com/compose/), go to the root directory and use:\n```\ndocker-compose up -d\n```\nThis will launch the project using a PostgreSQL database.\n\n### Swagger Documentation\nOnce the system is running, navigate to http://localhost:8080/\nto view the Swagger documentation.\n\n## Technology\n- [JDK25](https://openjdk.org/projects/jdk/25/) - Latest JDK with long-term support\n- [Gradle](https://github.com/gradle/gradle) - Used for compilation, building, testing and dependency management\n- [Spring Boot Web MVC](https://github.com/spring-projects/spring-boot) - For creating REST APIs\n- [Springdoc](https://github.com/springdoc/springdoc-openapi) - Provides Swagger documentation for REST APIs\n- [Spring Data JPA](https://docs.spring.io/spring-data/jpa/reference/index.html) - Repository support for JPA\n- [PostgreSQL](https://www.postgresql.org/) - Open-source relational database\n- [H2database](https://github.com/h2database/h2database) - Provides an in-memory database for simple local testing\n- [Liquibase](https://github.com/liquibase/liquibase) - Used to manage database schema changelogs\n- [Lombok](https://github.com/projectlombok/lombok) - Used to reduce boilerplate code\n- [Testcontainers](https://github.com/testcontainers) - Creates a temporary PostgreSQL database for tests\n\n## Testing\nYou can run the tests for this project using the following command:\n```\n./gradlew test\n```\nPlease note that this project uses\n[Testcontainers](https://github.com/testcontainers)\nto create a temporary PostgreSQL database for tests. This requires\na local Docker instance to be running when executing the tests.\n\n## Gradle best practices\n[docs.gradle.org](https://docs.gradle.org/current/userguide/performance.html) - [kotlinlang.org](https://kotlinlang.org/docs/gradle-best-practices.html)\n\n### Preface\nThis project uses Java but the linked article above is generally meant \nfor Kotlin projects. However, I still think that the recommended best \npractices for Gradle are relevant for a Java project as well. \nThe recommendations can be useful for all sorts of Gradle projects.\n\n### ✅ Use Kotlin DSL\nThis project uses Kotlin DSL instead of the traditional Groovy DSL by\nusing **build.gradle.kts** files instead of **build.gradle** files.\nThis gives us the benefits of strict typing which lets IDEs provide\nbetter support for refactoring and auto-completion.\nIf you want to read more about the benefits of using\nKotlin DSL over Groovy DSL, you can check out\n[gradle-kotlin-dsl-vs-groovy-dsl](https://github.com/thorlauridsen/gradle-kotlin-dsl-vs-groovy-dsl)\n\n### ✅ Use a version catalog\n\nThis project uses a version catalog\n[local.versions.toml](gradle/local.versions.toml)\nwhich allows us to centralize dependency management.\nWe can define versions, libraries, bundles and plugins here.\nThis enables us to use Gradle dependencies consistently across the entire project.\n\nDependencies can then be implemented in a specific **build.gradle.kts** file as such:\n```kotlin\nimplementation(local.spring.boot.starter)\n```\n\nThe Kotlinlang article says to name the version catalog **libs.versions.toml**\nbut for this project it has been named **local.versions.toml**. The reason\nfor this is that we can create a shared common version catalog which can\nbe used across Gradle projects. Imagine that you are working on multiple\nsimilar Gradle projects with different purposes, but each project has some\nspecific dependencies but also some dependencies in common. The dependencies\nthat are common across projects could be placed in the shared version catalog\nwhile specific dependencies are placed in the local version catalog.\n\n### ✅ Use local build cache\n\nThis project uses a local\n[build cache](https://docs.gradle.org/current/userguide/build_cache.html)\nfor Gradle which is a way to increase build performance because it will\nre-use outputs produced by previous builds. It will store build outputs\nlocally and allow subsequent builds to fetch these outputs from the cache\nwhen it knows that the inputs have not changed.\nThis means we can save time building\n\nGradle build cache is disabled by default so it has been enabled for this\nproject by updating the root [gradle.properties](gradle.properties) file:\n```properties\norg.gradle.caching=true\n```\n\nThis is enough to enable the local build cache\nand by default, this will use a directory in the Gradle User Home\nto store build cache artifacts.\n\n### ✅ Use configuration cache\n\nThis project uses\n[Gradle configuration cache](https://docs.gradle.org/current/userguide/configuration_cache.html)\nand this will improve build performance by caching the result of the\nconfiguration phase and reusing this for subsequent builds. This means\nthat Gradle tasks can be executed faster if nothing has been changed\nthat affects the build configuration. If you update a **build.gradle.kts**\nfile, the build configuration has been affected.\n\nThis is not enabled by default, so it is enabled by defining this in\nthe root [gradle.properties](gradle.properties) file:\n```properties\norg.gradle.configuration-cache=true\norg.gradle.configuration-cache.parallel=true\n```\n\n### ✅ Use modularization\n\nThis project uses modularization to create a\n[multi-project Gradle build](https://docs.gradle.org/current/userguide/multi_project_builds.html).\nThe benefit here is that we optimize build performance and structure our\nentire project in a meaningful way. This is more scalable as it is easier\nto grow a large project when you structure the code like this.\n\n```\nroot\n│─ build.gradle.kts\n│─ settings.gradle.kts\n│─ apps\n│   └─ api\n│       └─ build.gradle.kts\n│─ modules\n│   ├─ model\n│   │   └─ build.gradle.kts\n│   └─ persistence\n│       └─ build.gradle.kts\n```\n\nThis also allows us to specifically decide which Gradle dependencies will be used\nfor which subproject. Each subproject should only use exactly the dependencies\nthat they need.\n\nSubprojects located under [apps](apps) are runnable, so this means we can\nrun the **api** project to spin up a Spring Boot REST API. We can add more\nsubprojects under [apps](apps) to create additional runnable microservices.\n\nSubprojects located under [modules](modules) are not independently runnable.\nThe subprojects are used to structure code into various layers. The **model**\nsubproject is the most inner layer and contains domain model classes and this\nsubproject knows nothing about any of the other subprojects. The purpose of\nthe **persistence** subproject is to manage the code responsible for\ninteracting with the database. We can add more non-runnable subprojects\nunder [modules](modules) if necessary. This could for example\nbe a third-party integration.\n\n---\n\n#### Subproject with other subproject as dependency\n\nThe subprojects in this repository may use other subprojects as dependencies.\n\nIn our root [settings.gradle.kts](settings.gradle.kts) we have added:\n```kotlin\nenableFeaturePreview(\"TYPESAFE_PROJECT_ACCESSORS\")\n```\nWhich allows us to add a subproject as a dependency in another subproject:\n\n```kotlin\ndependencies {\n    implementation(projects.model)\n}\n```\n\nThis essentially allows us to define this structure:\n\n```\napi  \n│─ model  \n└─ persistence\n\npersistence  \n└─ model\n\nmodel has no dependencies\n```\n\n## Meta\n\nThis project has been inspired from the Kotlin project:\n[thorlauridsen/spring-boot-kotlin-sample](https://github.com/thorlauridsen/spring-boot-kotlin-sample).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthorlauridsen%2Fspring-boot-java-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthorlauridsen%2Fspring-boot-java-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthorlauridsen%2Fspring-boot-java-sample/lists"}