Skip to content

Commit

Permalink
dto incremental compile
Browse files Browse the repository at this point in the history
  • Loading branch information
Enaium committed Dec 6, 2024
1 parent 96bc8d7 commit 8d3e126
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "cn.enaium"
version = "0.0.16"
version = "0.0.18"

repositories {
mavenCentral()
Expand Down
59 changes: 42 additions & 17 deletions src/main/kotlin/cn/enaium/jimmer/gradle/JimmerPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import cn.enaium.jimmer.gradle.task.GenerateEntityTask
import cn.enaium.jimmer.gradle.utility.*
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.internal.tasks.JvmConstants

/**
Expand Down Expand Up @@ -170,34 +171,58 @@ class JimmerPlugin : Plugin<Project> {
}
}

if (afterProject.tasks.hasKsp && extension.language.get() == Language.KOTLIN) {
if (afterProject.tasks.hasCompileKotlin && afterProject.tasks.hasKsp && extension.language.get() == Language.KOTLIN) {
afterProject.rootProject.tasks.also {
if (it.hasPre) {
it.getByName(PRE_TASK_NAME).dependsOn(afterProject.tasks.getByName(KSP_TASK_NAME))
}
}
}

afterProject.tasks.kspKotlin { kspKotlin ->
kspArguments(afterProject.extensions.getByName("ksp"))[DTO_DIRS]?.let { dirs ->
dirs.split("\\s*[,:;]\\s*".toRegex()).mapNotNull {
when {
it == "" || it == "/" -> null
it.startsWith("/") -> it.substring(1)
it.endsWith("/") -> it.substring(0, it.length - 1)
else -> it.takeIf { it.isNotEmpty() }
}
}.toSet().forEach {
kspKotlin.inputs.dir(it)
}
} ?: let {
val dir = afterProject.layout.projectDirectory.dir("src").file("main/dto/")
if (dir.asFile.exists()) {
kspKotlin.inputs.dir(dir)
fun addInputs(task: Task) {
kspArguments(afterProject.extensions.getByName("ksp"))[DTO_DIRS]?.let { dirs ->
dirs.split("\\s*[,:;]\\s*".toRegex()).mapNotNull {
when {
it == "" || it == "/" -> null
it.startsWith("/") -> it.substring(1)
it.endsWith("/") -> it.substring(0, it.length - 1)
else -> it.takeIf { it.isNotEmpty() }
}
}.toSet().forEach {
task.inputs.dir(it)
}
} ?: let {
val dir = afterProject.layout.projectDirectory.dir("src").file("main/dto/")
if (dir.asFile.exists()) {
task.inputs.dir(dir)
}
}
}

if (afterProject.tasks.hasCompileKotlin) {
afterProject.tasks.compileKotlin { compileKotlin ->
addInputs(compileKotlin)
}
}

if (afterProject.tasks.hasCompileDebugKotlin) {
afterProject.tasks.compileDebugKotlin { compileDebugKotlin ->
addInputs(compileDebugKotlin)
}
}

if (afterProject.tasks.hasKsp) {
afterProject.tasks.kspKotlin { kspKotlin ->
addInputs(kspKotlin)
}
}

if (afterProject.tasks.hasDebugKsp) {
afterProject.tasks.kspDebugKotlin { kspDebugKotlin ->
addInputs(kspDebugKotlin)
}
}

// Add spring-boot-starter,sql,sql-kotlin
if (afterProject.plugins.hasSpringBoot && !afterProject.hasDependency(JIMMER_SPRINGBOOT_NAME)) {
afterProject.dependencies.implementation(
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/cn/enaium/jimmer/gradle/utility/const.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const val IMMUTABLE_IS_MODULE_REQUIRED = "jimmer.immutable.isModuleRequired"
const val KSP_PLUGIN_ID = "com.google.devtools.ksp"
const val SPRINGBOOT_PLUGIN_ID = "org.springframework.boot"
const val KSP_TASK_NAME = "kspKotlin"
const val KSP_DEBUG_TASK_NAME = "kspDebugKotlin"
const val JIMMER_GROUP = "org.babyfish.jimmer"
const val JIMMER_SPRINGBOOT_NAME = "jimmer-spring-boot-starter"
const val JIMMER_SQL_NAME = "jimmer-sql"
Expand Down
27 changes: 27 additions & 0 deletions src/main/kotlin/cn/enaium/jimmer/gradle/utility/task.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,21 @@ import org.gradle.api.tasks.compile.JavaCompile
internal val TaskContainer.hasKsp: Boolean
get() = findByName(KSP_TASK_NAME) != null

internal val TaskContainer.hasDebugKsp: Boolean
get() = findByName(KSP_DEBUG_TASK_NAME) != null

internal val TaskContainer.hasPre: Boolean
get() = findByName(PRE_TASK_NAME) != null

internal val TaskContainer.hasCompileJava: Boolean
get() = findByName("compileJava") != null

internal val TaskContainer.hasCompileKotlin: Boolean
get() = findByName("compileKotlin") != null

internal val TaskContainer.hasCompileDebugKotlin: Boolean
get() = findByName("compileDebugKotlin") != null

internal fun TaskContainer.compileJava(action: (JavaCompile) -> Unit) {
withType(JavaCompile::class.java) {
action(it)
Expand All @@ -42,4 +51,22 @@ internal fun TaskContainer.kspKotlin(action: (Task) -> Unit) {
getByName(KSP_TASK_NAME) {
action(it)
}
}

internal fun TaskContainer.kspDebugKotlin(action: (Task) -> Unit) {
getByName(KSP_DEBUG_TASK_NAME) {
action(it)
}
}

internal fun TaskContainer.compileKotlin(action: (Task) -> Unit) {
getByName("compileKotlin") {
action(it)
}
}

internal fun TaskContainer.compileDebugKotlin(action: (Task) -> Unit) {
getByName("compileDebugKotlin") {
action(it)
}
}

0 comments on commit 8d3e126

Please sign in to comment.