Skip to content

Commit

Permalink
fix: decouple views-gradle-plugin from dependency on `grails-gradle…
Browse files Browse the repository at this point in the history
…-plugin`

The decoupling is intended to mitigate potential circular dependency issues during releases.
  • Loading branch information
matrei committed Dec 21, 2024
1 parent fedfcf0 commit 4de50df
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
1 change: 0 additions & 1 deletion gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ dependencies {
// the gradle api is provided by java-gradle-plugin

implementation platform(libs.grails.bom)
implementation libs.grails.gradle.plugin
implementation libs.jakarta.annotation.api

compileOnly libs.groovy.core // @CompileStatic
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package grails.views.gradle

import grails.views.gradle.util.GrailsNameUtils
import grails.views.gradle.util.SourceSets
import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import org.apache.tools.ant.taskdefs.condition.Os
Expand All @@ -12,9 +13,6 @@ import org.gradle.api.file.FileCollection
import org.gradle.api.tasks.SourceSetOutput
import org.gradle.api.tasks.TaskContainer
import org.gradle.api.tasks.bundling.Jar
import org.grails.gradle.plugin.core.GrailsExtension
import org.grails.gradle.plugin.core.IntegrationTestGradlePlugin
import org.grails.gradle.plugin.util.SourceSets

/**
* Abstract implementation of a plugin that compiles views
Expand Down Expand Up @@ -42,6 +40,7 @@ class AbstractGroovyTemplatePlugin implements Plugin<Project> {
}

@Override
@CompileDynamic
void apply(Project project) {
TaskContainer tasks = project.tasks
String upperCaseName = GrailsNameUtils.getClassName(fileExtension)
Expand All @@ -54,8 +53,8 @@ class AbstractGroovyTemplatePlugin implements Plugin<Project> {
File destDir = new File(project.layout.buildDirectory.get().asFile, "${templateCompileTask.fileExtension.get()}-classes/main")
output?.dir(destDir)
project.afterEvaluate {
GrailsExtension grailsExt = project.extensions.getByType(GrailsExtension)
if (grailsExt.pathingJar && Os.isFamily(Os.FAMILY_WINDOWS)) {
def grailsExt = project.extensions.findByName('grails')
if (grailsExt?.pathingJar && Os.isFamily(Os.FAMILY_WINDOWS)) {
Jar pathingJar = (Jar) tasks.named('pathingJar').get()
ConfigurableFileCollection allClasspath = project.files(
"${project.layout.buildDirectory.get().asFile}/classes/groovy/main",
Expand Down Expand Up @@ -83,7 +82,7 @@ class AbstractGroovyTemplatePlugin implements Plugin<Project> {
task.dependsOn(templateCompileTask)
}
}
project.plugins.withType(IntegrationTestGradlePlugin).configureEach {
project.plugins.withId('org.grails.gradle.plugin.core.IntegrationTestGradlePlugin') {
tasks.named('compileIntegrationTestGroovy') { Task task ->
task.dependsOn(templateCompileTask)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package grails.views.gradle.util

import groovy.transform.CompileStatic
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.SourceSetContainer

/**
* Copied from grails-gradle-plugin to remove the dependency on that plugin.
* This is a possible candidate for a future "grails-common" module.
*
* @author Graeme Rocher
* @since 3.0
*/
@CompileStatic
class SourceSets {

/**
* Finds the main SourceSet for the project
* @param project The project
* @return The main source set or null if it can't be found
*/
static SourceSet findMainSourceSet(Project project) {
return findSourceSet(project, SourceSet.MAIN_SOURCE_SET_NAME)
}

/**
* Finds the main SourceSet for the project
* @param project The project
* @return The main source set or null if it can't be found
*/
static SourceSet findSourceSet(Project project, String name) {
SourceSetContainer sourceSets = findSourceSets(project)
return sourceSets?.find { SourceSet sourceSet ->
sourceSet.name == name
} as SourceSet
}

static SourceSetContainer findSourceSets(Project project) {
JavaPluginExtension plugin = project.extensions.getByType(JavaPluginExtension)
SourceSetContainer sourceSets = plugin?.sourceSets
return sourceSets
}
}

0 comments on commit 4de50df

Please sign in to comment.