Skip to content

Enaium/jimmer-gradle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jimmer-gradle

GitHub top language Gradle Plugin Portal Version

Feature

  • Generate code for database table, column and association.
  • Incremental compile for dto language (apt/ksp).
  • Add implementation (spring-boot-start/sql/sql-kotlin) for dependencies.
  • Add annotationProcessor/ksp for dependencies.
  • Easy to add arguments for annotationProcessor/ksp.
  • Can use jimmer's catalog in the project.
  • Let jimmer generate code when opening the project for the first time.

Usage(Recommended Method 2)

Warning: You cannot use the method 1 and method 2 at the same time.

Gradle Project Plugin(Method 1)

In the build.gradle.kts file, you can use the following code to apply the plugin.

plugins {
    id("cn.enaium.jimmer.gradle") version "latest.release"
}

If you also used kotlin, you need to declare the ksp plugin before the jimmer plugin.

plugins {
    kotlin("jvm") version "2.0.21"
    id("com.google.devtools.ksp") version "2.0.21+"
    id("cn.enaium.jimmer.gradle") version "latest.release"
}

Gradle Settings Plugin(Method 2)

In the settings.gradle.kts file, you can use the following code to apply the plugin.

plugins {
    id("cn.enaium.jimmer.gradle.setting") version "latest.release"
}

If you want to modify the extension of the gradle project plugin, then you can use the gradle project plugin.

plugins {
    alias(jimmers.plugins.jimmer)
}

If you also used kotlin, you need to declare the ksp plugin before the jimmer plugin.

plugins {
    kotlin("jvm") version "2.0.21"
    alias(jimmers.plugins.ksp) version "2.0.21+"
    alias(jimmers.plugins.jimmer)
}

then you need to add the ksp dependency in the build.gradle.kts file.

dependencies {
    ksp(jimmers.ksp)
}

Jimmer's Version(Both Gradle Project Plugin and Gradle Settings Plugin)

Warning: The version of the extension is not supported for ksp when issue #1789 isn't fixed, but you can use the latest version or use the gradle setting plugin.

In the build.gradle.kts file if you use the gradle project plugin, or in the settings.gradle.kts file if you use the gradle settings plugin, you can use the following code to set the version of jimmer.

jimmer {
    version.set("latest.release")//default latest
}

Generate Entity(Only Gradle Project Plugin)

Static Badge Static Badge

Static Badge Static Badge Static Badge

import cn.enaium.jimmer.gradle.extension.Association
import cn.enaium.jimmer.gradle.extension.Driver

plugins {
    //...
    id("cn.enaium.jimmer.gradle") version "<version>"
}

dependencies {
    //...
    implementation("org.postgresql:postgresql:42.6.0")//require jdbc driver
}

jimmer {
    generator {
        target {
            srcDir.set("src/main/kotlin")
            packageName.set("cn.enaium")
        }
        jdbc {
            driver.set(Driver.POSTGRESQL)//Driver.POSTGRESQL,Driver.MARIADB,Driver.MYSQL, no default
            url.set("jdbc:postgresql://localhost:5432/postgres")
            username.set("postgres")
            password.set("postgres")
        }
        table {
            idView.set(true)
            comment.set(true)
            primaryKey.set("id")//default id
            association.set(Association.REAL)//Association.REAL,Association.FAKE,Association.NO, default Association.REAL
            typeMappings.set(
                mapOf(
                    "float8" to "kotlin.Float",
                )
            )
        }
    }
}

Association(Only Gradle Project Plugin)

You must add the suffix '_id'(primaryKey.set("id")) to the column name if the column is a fake foreign key, otherwise the column cannot be recognized as a foreign key.

If you want to use the fake foreign key, you need to set the association.set(Association.FAKE), otherwise the default is association.set(Association.REAL), of course you can also set association.set(Association.NO) to disable the association.

Warning: You can't use the fake association if you included the real association in the database.

jimmer {
    generator {
        table {
            primaryKey.set("id")
            association.set(Association.REAL)
        }
    }
}

typeMappings(Only Gradle Project Plugin)

default

You can customize the type mapping, the default is as follows:

jimmer {
    generator {
        table {
            typeMappings.set(
                mapOf(
                    "float8" to "kotlin.Float",//Java: "java.lang.Float"
                )
            )
        }
    }
}

Dto Incremental Compile

Open the dto file and press Ctrl + F9 to compile the dto file.

implementation for dependencies

spring-boot-start

plugins {
    id("org.springframework.boot")//require
}

It will automatically add or use the catalog of jimmer if you use the gradle settings plugin.

dependencies {
    implementation(jimmers.springBootStart)
}

sql-kotlin

It will automatically add or use the catalog of jimmer if you use the gradle settings plugin.

dependencies {
    implementation(jimmers.sqlKotlin)
}

sql

It will automatically add or use the catalog of jimmer if you use the gradle settings plugin.

dependencies {
    implementation(jimmers.sql)
}

annotationProcessor/ksp for dependencies

ksp

It will automatically add or use the catalog of jimmer if you use the gradle settings plugin.

plugins {
    kotlin("jvm") version "2.0.21"
    id("com.google.devtools.ksp") version "2.0.21+" //require and must declare before jimmer gradle plugin
}
plugins {
    kotlin("jvm") version "2.0.21"
    alias(jimmers.plugins.ksp) version "2.0.21+"
}
dependencies {
    ksp(jimmers.ksp)
}

annotationProcessor

It will automatically add or use the catalog of jimmer if you use the gradle settings plugin.

dependencies {
    annotationProcessor(jimmers.apt)
}

annotationProcessor/ksp arguments(Only Gradle Project Plugin)

jimmer {
    entry {
        objects.set("Drafts")//equal to -Ajimmer.entry.objects=Drafts
    }
}

Gradle Project Plugin Extension

extension type default description
version String latest.release Jimmer version.
keepIsPrefix Boolean false Keep 'is' prefix in getter method.
generator cn.enaium.jimmer.gradle.extension.Generator Entity generator.
generator.target cn.enaium.jimmer.gradle.extension.Target Entity generator target.
generator.target.srcDir String Entity generator target src dir.
generator.target.packageName String Entity generator target package.
generator.jdbc cn.enaium.jimmer.gradle.extension.Jdbc For database connection.
generator.jdbc.driver cn.enaium.jimmer.gradle.extension.Driver Database driver.
generator.jdbc.url String Database url.
generator.jdbc.username String Database username.
generator.jdbc.password String Database password.
generator.table cn.enaium.jimmer.gradle.extension.Table Table rule.
generator.table.primaryKey String id Table primary key name.
generator.table.asociation cn.enaium.jimmer.gradle.extension.Association REAL Table association rule.
generator.table.typeMappings Map<String, String> default Column type mapping.
generator.table.comment Boolean false Generate table comment.
generator.table.idView Boolean false Generate id view.
generator.poet cn.enaium.jimmer.gradle.extension.Poet Poet rule.
generator.poet.indent String Four spaces Poet indent.
client.checkedExceptions Boolean
client.ignoreJdkWarning Boolean Java only.
dto.dirs List<String>
dto.testDirs List<String>
dto.mutable Boolean Kotlin only.
dto.defaultNullableInputModifier cn.enaium.jimmer.gradle.extension.InputDtoModifier
dto.hibernateValidatorEnhancement Boolean Java only.
entry cn.enaium.jimmer.gradle.extension.Entry Java only.
entry.objects String Generate objects class name, java only.
entry.tables String Generate tables class name, java only.
entry.tableExes String Generate tableExes class name, java only.
entry.fetchers String Generate fetchers class name, java only.
immutable.isModuleRequired Boolean Kotlin only.
source.includes List<String> Java only.
source.excludes List<String> Java only.

Gradle Settings Plugin Extension

extension type default description
version String latest.release Jimmer version.