Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Grails plugin assemble task produces only a JAR artifact #369

Merged
merged 3 commits into from
Dec 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -36,7 +35,6 @@ import org.gradle.api.tasks.compile.GroovyCompile
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 @@ -68,9 +66,11 @@ class GrailsPluginGradlePlugin extends GrailsGradlePlugin {
configureProjectNameAndVersionASTMetadata(project)
}

configureAssembleTask(project)

configurePluginResources(project)

configurePluginJarTask(project)
configureJarTask(project)

configureSourcesJarTask(project)

Expand Down Expand Up @@ -186,14 +186,34 @@ 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
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) {
it.enabled = true
it.archiveClassifier.set('') // Remove '-plain' suffix from jar file name
it.exclude('application.yml', 'application.groovy', 'logback.groovy', 'logback.xml')
}

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')
}
}

Expand Down
Loading