Skip to content

Commit

Permalink
fix: configure assemble to produce only a plain JAR
Browse files Browse the repository at this point in the history
Disable tasks for bootable artifacts (e.g., `bootJar`, `bootWar`, etc.) and other outputs like war.
  • Loading branch information
matrei committed Dec 26, 2024
1 parent 3cb7bcc commit 0948200
Showing 1 changed file with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -69,9 +66,11 @@ class GrailsPluginGradlePlugin extends GrailsGradlePlugin {
configureProjectNameAndVersionASTMetadata(project)
}

configureAssembleTask(project)

configurePluginResources(project)

configurePluginJarTask(project)
configureJarTask(project)

configureSourcesJarTask(project)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0948200

Please sign in to comment.