diff --git a/build.gradle.kts b/build.gradle.kts index 62b87cd..fcca06f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ plugins { } group = "cn.enaium" -version = "0.0.18" +version = "${properties["version"]}" repositories { mavenCentral() @@ -17,6 +17,7 @@ dependencies { implementation(libs.javapoet) implementation(libs.jetbrainsAnnotations) implementation(libs.jimmer) + implementation(libs.jackson) testImplementation(libs.testcontainers.postgresql) testImplementation(libs.testcontainers.mariadb) testImplementation(libs.testcontainers.mysql) diff --git a/gradle.properties b/gradle.properties index 3cd28d0..409b0f3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,9 +1,2 @@ kotlin.code.style=official -kotlinpoet=1.16.0 -javapoet=1.13.0 -testcontainers=1.19.6 -postgresql=42.6.0 -mariadb=3.3.3 -mysql=8.3.0 -jimmer=0.8.131 -jetbrainsAnnotations=24.1.0 \ No newline at end of file +version=0.0.19 \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0168ecc..73ef1e1 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,14 +7,16 @@ testcontainers = "1.19.7" postgresql = "42.7.3" mariadb = "3.3.3" mysql = "8.3.0" -jimmer = "0.9.25" +jimmer = "0.9.35" jetbrainsAnnotations = "24.1.0" +jackson = "2.18.2" [libraries] kotlinpoet = { module = "com.squareup:kotlinpoet", version.ref = "kotlinpoet" } javapoet = { module = "com.squareup:javapoet", version.ref = "javapoet" } jetbrainsAnnotations = { module = "org.jetbrains:annotations", version.ref = "jetbrainsAnnotations" } jimmer = { module = "org.babyfish.jimmer:jimmer-core", version.ref = "jimmer" } +jackson = { module = "com.fasterxml.jackson.core:jackson-core", version.ref = "jackson" } testcontainers-postgresql = { module = "org.testcontainers:postgresql", version.ref = "testcontainers" } testcontainers-mariadb = { module = "org.testcontainers:mariadb", version.ref = "testcontainers" } testcontainers-mysql = { module = "org.testcontainers:mysql", version.ref = "testcontainers" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 589bc3b..03a7966 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Wed Feb 21 13:43:28 CST 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/kotlin/cn/enaium/jimmer/gradle/JimmerPlugin.kt b/src/main/kotlin/cn/enaium/jimmer/gradle/JimmerPlugin.kt index f32ded7..c603742 100644 --- a/src/main/kotlin/cn/enaium/jimmer/gradle/JimmerPlugin.kt +++ b/src/main/kotlin/cn/enaium/jimmer/gradle/JimmerPlugin.kt @@ -19,6 +19,7 @@ package cn.enaium.jimmer.gradle import cn.enaium.jimmer.gradle.extension.JimmerExtension import cn.enaium.jimmer.gradle.extension.Language import cn.enaium.jimmer.gradle.task.GenerateEntityTask +import cn.enaium.jimmer.gradle.task.GenerateLspDependenciesTask import cn.enaium.jimmer.gradle.utility.* import org.gradle.api.Plugin import org.gradle.api.Project @@ -43,9 +44,9 @@ class JimmerPlugin : Plugin { } project.afterEvaluate { afterProject -> - afterProject.tasks.create("generateEntity", GenerateEntityTask::class.java) { - it.group = "jimmer" - } + val generateEntity = afterProject.tasks.register("generateEntity", GenerateEntityTask::class.java) + val generateLspDependencies = + afterProject.tasks.register("generateLspDependencies", GenerateLspDependenciesTask::class.java) if (extension.language.get() == Language.JAVA) { afterProject.tasks.compileJava { compile -> @@ -143,6 +144,7 @@ class JimmerPlugin : Plugin { } } afterProject.tasks.compileJava { compile -> + compile.dependsOn(generateLspDependencies) compile.options.compilerArgs.firstOrNull { it.startsWith("-A$DTO_DIRS=") }?.let { @@ -180,6 +182,7 @@ class JimmerPlugin : Plugin { } fun addInputs(task: Task) { + task.dependsOn(generateLspDependencies) kspArguments(afterProject.extensions.getByName("ksp"))[DTO_DIRS]?.let { dirs -> dirs.split("\\s*[,:;]\\s*".toRegex()).mapNotNull { when { diff --git a/src/main/kotlin/cn/enaium/jimmer/gradle/task/GenerateEntityTask.kt b/src/main/kotlin/cn/enaium/jimmer/gradle/task/GenerateEntityTask.kt index a7e6f31..a87d992 100644 --- a/src/main/kotlin/cn/enaium/jimmer/gradle/task/GenerateEntityTask.kt +++ b/src/main/kotlin/cn/enaium/jimmer/gradle/task/GenerateEntityTask.kt @@ -36,6 +36,12 @@ import java.util.logging.Logger * @author Enaium */ open class GenerateEntityTask : DefaultTask() { + + init { + group = "jimmer" + description = "Generate entity" + } + @TaskAction fun generateEntity() { val extension = project.extensions.getByType(JimmerExtension::class.java) diff --git a/src/main/kotlin/cn/enaium/jimmer/gradle/task/GenerateLspDependenciesTask.kt b/src/main/kotlin/cn/enaium/jimmer/gradle/task/GenerateLspDependenciesTask.kt new file mode 100644 index 0000000..664c0c6 --- /dev/null +++ b/src/main/kotlin/cn/enaium/jimmer/gradle/task/GenerateLspDependenciesTask.kt @@ -0,0 +1,66 @@ +/* + * Copyright 2024 Enaium + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.enaium.jimmer.gradle.task + +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.databind.node.ArrayNode +import com.fasterxml.jackson.databind.node.JsonNodeFactory +import com.fasterxml.jackson.databind.node.ObjectNode +import org.gradle.api.DefaultTask +import org.gradle.api.tasks.TaskAction +import java.io.File +import kotlin.io.path.* + +/** + * @author Enaium + */ +open class GenerateLspDependenciesTask : DefaultTask() { + init { + group = "jimmer" + description = "Generate dependencies for LSP" + } + + @TaskAction + fun generateLspDependency() { + val lspHome = Path(System.getProperty("user.home")).resolve("jimmer-dto-lsp") + + if (lspHome.resolve("server.jar").exists().not()) { + return + } + + val dependenciesFile = lspHome.resolve("dependencies.json") + + if (dependenciesFile.exists().not()) { + dependenciesFile.createParentDirectories() + dependenciesFile.createFile() + dependenciesFile.writeText("{}") + } + + val dependenciesJson = ObjectMapper().readTree(dependenciesFile.readText()) + val dependencies = project.configurations.named("runtimeClasspath").get() + + (dependenciesJson as ObjectNode).set( + project.projectDir.absolutePath, + JsonNodeFactory.instance.arrayNode().apply { + dependencies.forEach { + add(it.absolutePath) + } + }) + + dependenciesFile.writeText(ObjectMapper().writeValueAsString(dependenciesJson)) + } +} \ No newline at end of file