Create a Project
Create a Spring Boot Project
Use https://start.spring.io/ to create a Spring Boot project. You need to choose your preferred language - Java or Kotlin.
The choice of language is important because Jimmer supports two different sets of APIs.
-
Java API - Ensures maximum developer usage
-
Kotlin API - APIs designed specifically for Kotlin to optimize the development experience
Add Dependencies
Jimmer itself is highly neutral and can be used without Spring Boot. But it also provides great integration with Spring Boot.
Users can choose to use it with or without Spring Boot. Different choices require adding different dependencies.
-
groupId: org.babyfish.jimmer
-
artifactId:
Integrate with Spring Boot Standalone Usage Java jimmer-spring-boot-starter jimmer-sql Kotlin jimmer-sql-kotlin
Compared to standalone usage, integrating with Spring Boot is simpler. So this tutorial will demonstrate the jimmer-spring-boot-starter
.
Modify build.gradle or pom.xml to add dependencies:
- Maven
- Gradle
- Gradle (Kts)
- Gradle Plugin
- Gradle Plugin (kts)
<properties>
<jimmer.version>0.9.20</jimmer.version>
</properties>
<dependencies>
<dependency>
<groupId>org.babyfish.jimmer</groupId>
<artifactId>jimmer-spring-boot-starter</artifactId>
<version>${jimmer.version}</version>
</dependency>
...other dependencies omitted...
</dependencies>
ext {
jimmerVersion = '0.9.20'
}
dependencies {
implementation "org.babyfish.jimmer:jimmer-spring-boot-starter:${jimmerVersion}"
...other dependencies omitted...
}
val jimmerVersion = "0.9.20"
dependencies {
implementation("org.babyfish.jimmer:jimmer-spring-boot-starter:${jimmerVersion}")
...other dependencies omitted...
}
plugins {
// Starting from Gradle 7.0, you can use "latest.release" instead of a specific version number to represent the use of the latest version.
// You can also use the '+' character to indicate matching the latest version number starting from the '+' character.
id "tech.argonariod.gradle-plugin-jimmer" version "latest.release"
... other plugins omitted ...
}
jimmer {
// Set the Jimmer dependency version, where you can also use version range expressions such as "latest.release" or "0.+"
version = "0.9.20"
}
plugins {
// Starting from Gradle 7.0, you can use "latest.release" instead of a specific version number to represent the use of the latest version.
// You can also use the '+' character to indicate matching the latest version number starting from the '+' character.
id("tech.argonariod.gradle-plugin-jimmer") version "latest.release"
... other plugins omitted ...
}
jimmer {
// Set the Jimmer dependency version, where you can also use version range expressions such as "latest.release" or "0.+"
version = "0.9.20"
}
If you are using Gradle as your build tool, you can also use third-party Gradle plugin tech.argonariod.gradle-plugin-jimmer
provided by the community to automatically identify the project type and add dependencies automatically.
The tech.argonariod.gradle-plugin-jimmer
gradle plugin is community-provided and maintained to simplify Jimmer project configuration, and it is not officially maintained by Jimmer.
Repository URL: https://github.com/ArgonarioD/gradle-plugin-jimmer
Additional Configuration Needed for Kotlin
If using Kotlin, you must modify the Spring Boot configuration file - this is very important.
Kotlin projects must configure jimmer.language
- application.properties
- application.yml
jimmer.language = kotlin
jimmer:
language: kotlin
Other Useful Configurations
In addition to the required jimmer.language
for Kotlin projects, there are other useful configurations.
Here are a few basic configurations that work for both Java and Kotlin:
Property | Type | Default | Description |
---|---|---|---|
jimmer.dialect | string | org.babyfish.jimmer.sql.dialect.DefaultDialect | Database dialect class name |
jimmer.show-sql | boolean | false | Print executed SQL if true |
jimmer.pretty-sql | boolean | false | Ensure that the printed SQL is well-formatted (compact by default) |
jimmer.database-validation-mode | NONE|WARNING|ERROR | NONE | Validate consistency between database schema and entity types. WARNING logs inconsistencies, ERROR throws errors. |
See Spring/Appendix for complete documentation on configurations.
- application.properties
- application.yml
jimmer.dialect = org.babyfish.jimmer.sql.dialect.MySqlDialect
jimmer.show-sql = true
jimmer.pretty-sql = true
jimmer.database-validation-mode = ERROR
...other configurations omitted...
jimmer:
dialect: org.babyfish.jimmer.sql.dialect.MySqlDialect
show-sql: true
pretty-sql: true
database-validation-mode: ERROR
...other configurations omitted...
Add Other Required Dependencies
In addition to Jimmer, some other dependencies are required like spring-web, JDBC driver, etc.
Modify build.gradle or pom.xml to add dependencies:
- Maven
- Gradle
- Gradle (Kts)
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.30</version>
<scope>runtime</scope>
</dependency>
...other dependencies omitted...
</dependencies>
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
runtimeOnly 'mysql:mysql-connector-java:8.0.30'
...other dependencies omitted...
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
runtimeOnly("mysql:mysql-connector-java:8.0.30")
...other dependencies omitted...
}