From 4c41a0e36d152583810845d196432cd51162ae91 Mon Sep 17 00:00:00 2001 From: Mattias Reichel Date: Wed, 11 Dec 2024 10:30:58 +0100 Subject: [PATCH 1/3] fix: ensure Grails plugin `assemble` task produces a JAR artifact Previously, running the `assemble` task in a Grails plugin project only generated `*.war` and `*-plain.war` artifacts. This change ensures that the task also produces the expected JAR artifact, aligning with typical plugin packaging needs. --- .../grails/gradle/plugin/core/GrailsPluginGradlePlugin.groovy | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePlugin.groovy b/src/main/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePlugin.groovy index 0bce211e..900328e5 100644 --- a/src/main/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePlugin.groovy +++ b/src/main/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePlugin.groovy @@ -33,6 +33,7 @@ import org.gradle.api.tasks.TaskContainer import org.gradle.api.tasks.TaskDependency import org.gradle.api.tasks.bundling.Jar import org.gradle.api.tasks.compile.GroovyCompile +import org.gradle.language.base.plugins.LifecycleBasePlugin import org.gradle.language.jvm.tasks.ProcessResources import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry import org.grails.gradle.plugin.util.SourceSets @@ -195,6 +196,9 @@ class GrailsPluginGradlePlugin extends GrailsGradlePlugin { it.archiveClassifier.set('') // Remove '-plain' suffix from jar file name it.exclude('application.yml', 'application.groovy', 'logback.groovy', 'logback.xml') } + project.tasks.named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME) { + it.dependsOn(JavaPlugin.JAR_TASK_NAME) // assemble task should produce the jar artifact + } } @CompileDynamic From 3cb7bcc4c23af0ad1e8104a07135f073e6e2317c Mon Sep 17 00:00:00 2001 From: Mattias Reichel Date: Wed, 11 Dec 2024 10:38:24 +0100 Subject: [PATCH 2/3] refactor: name task configuration closure parameters for clarity --- .../plugin/core/GrailsPluginGradlePlugin.groovy | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePlugin.groovy b/src/main/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePlugin.groovy index 900328e5..93d7e96b 100644 --- a/src/main/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePlugin.groovy +++ b/src/main/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePlugin.groovy @@ -188,16 +188,16 @@ class GrailsPluginGradlePlugin extends GrailsGradlePlugin { } protected void configurePluginJarTask(Project project) { - project.tasks.named(SpringBootPlugin.BOOT_JAR_TASK_NAME) { - it.enabled = false // Grails Plugins should not produce a bootJar + project.tasks.named(SpringBootPlugin.BOOT_JAR_TASK_NAME) { Task bootJarTask -> + bootJarTask.enabled = false // Grails Plugins should not produce a bootJar } - project.tasks.named(JavaPlugin.JAR_TASK_NAME, Jar) { - it.enabled = true - it.archiveClassifier.set('') // Remove '-plain' suffix from jar file name - it.exclude('application.yml', 'application.groovy', 'logback.groovy', 'logback.xml') + project.tasks.named(JavaPlugin.JAR_TASK_NAME, Jar) { Jar jarTask -> + jarTask.enabled = true + jarTask.archiveClassifier.set('') // Remove '-plain' suffix from jar file name + jarTask.exclude('application.yml', 'application.groovy', 'logback.groovy', 'logback.xml') } - project.tasks.named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME) { - it.dependsOn(JavaPlugin.JAR_TASK_NAME) // assemble task should produce the jar artifact + project.tasks.named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME) { Task assembleTask -> + assembleTask.dependsOn(JavaPlugin.JAR_TASK_NAME) // assemble task should produce the jar artifact } } From 0948200f353d2514b487a91092cb6a6e58404516 Mon Sep 17 00:00:00 2001 From: Mattias Reichel Date: Thu, 26 Dec 2024 14:42:00 +0100 Subject: [PATCH 3/3] fix: configure `assemble` to produce only a plain JAR Disable tasks for bootable artifacts (e.g., `bootJar`, `bootWar`, etc.) and other outputs like war. --- .../core/GrailsPluginGradlePlugin.groovy | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/main/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePlugin.groovy b/src/main/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePlugin.groovy index 93d7e96b..2aaa3062 100644 --- a/src/main/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePlugin.groovy +++ b/src/main/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePlugin.groovy @@ -24,7 +24,6 @@ import org.gradle.api.artifacts.ConfigurationContainer import org.gradle.api.artifacts.PublishArtifact import org.gradle.api.file.DuplicatesStrategy import org.gradle.api.internal.tasks.DefaultTaskDependency -import org.gradle.api.plugins.JavaPlugin import org.gradle.api.tasks.Copy import org.gradle.api.tasks.JavaExec import org.gradle.api.tasks.SourceSet @@ -33,11 +32,9 @@ import org.gradle.api.tasks.TaskContainer import org.gradle.api.tasks.TaskDependency import org.gradle.api.tasks.bundling.Jar import org.gradle.api.tasks.compile.GroovyCompile -import org.gradle.language.base.plugins.LifecycleBasePlugin import org.gradle.language.jvm.tasks.ProcessResources import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry import org.grails.gradle.plugin.util.SourceSets -import org.springframework.boot.gradle.plugin.SpringBootPlugin import org.springframework.boot.gradle.tasks.bundling.BootJar import javax.inject.Inject @@ -69,9 +66,11 @@ class GrailsPluginGradlePlugin extends GrailsGradlePlugin { configureProjectNameAndVersionASTMetadata(project) } + configureAssembleTask(project) + configurePluginResources(project) - configurePluginJarTask(project) + configureJarTask(project) configureSourcesJarTask(project) @@ -187,18 +186,35 @@ class GrailsPluginGradlePlugin extends GrailsGradlePlugin { } } - protected void configurePluginJarTask(Project project) { - project.tasks.named(SpringBootPlugin.BOOT_JAR_TASK_NAME) { Task bootJarTask -> - bootJarTask.enabled = false // Grails Plugins should not produce a bootJar + protected void configureAssembleTask(Project project) { + // Assemble task in Grails Plugins should only produce a plain jar + project.tasks.named('assemble') { Task assembleTask -> + def disabledTasks = [ + 'bootDistTar', + 'bootDistZip', + 'bootJar', + 'bootStartScripts', + 'bootWar', + 'bootWarMainClassName', + 'distTar', + 'distZip', + 'startScripts', + 'war' + ] + disabledTasks.each { String disabledTaskName -> + project.tasks.findByName(disabledTaskName)?.enabled = false + } + // By default the assemble task does not create a plain jar + assembleTask.dependsOn('jar') } - project.tasks.named(JavaPlugin.JAR_TASK_NAME, Jar) { Jar jarTask -> + } + + protected void configureJarTask(Project project) { + project.tasks.named('jar', Jar) { Jar jarTask -> jarTask.enabled = true jarTask.archiveClassifier.set('') // Remove '-plain' suffix from jar file name jarTask.exclude('application.yml', 'application.groovy', 'logback.groovy', 'logback.xml') } - project.tasks.named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME) { Task assembleTask -> - assembleTask.dependsOn(JavaPlugin.JAR_TASK_NAME) // assemble task should produce the jar artifact - } } @CompileDynamic