diff --git a/gradle-plugin/build.gradle b/gradle-plugin/build.gradle index 1c75f55d9..97729c826 100644 --- a/gradle-plugin/build.gradle +++ b/gradle-plugin/build.gradle @@ -13,12 +13,7 @@ dependencies { // the gradle api is provided by java-gradle-plugin implementation platform(libs.grails.bom) - implementation libs.grails.bootstrap, { - // grails-bootstrap leaks groovy-xml which is a problem for Gradle (version conflict) - exclude group: 'org.codehaus.groovy', module: 'groovy-xml' - } implementation libs.grails.gradle.plugin - implementation libs.spring.boot.gradle.plugin implementation libs.jakarta.annotation.api compileOnly libs.groovy.core // @CompileStatic diff --git a/gradle-plugin/src/main/groovy/grails/views/gradle/AbstractGroovyTemplatePlugin.groovy b/gradle-plugin/src/main/groovy/grails/views/gradle/AbstractGroovyTemplatePlugin.groovy index 2d2acf4f4..56c39b8d7 100644 --- a/gradle-plugin/src/main/groovy/grails/views/gradle/AbstractGroovyTemplatePlugin.groovy +++ b/gradle-plugin/src/main/groovy/grails/views/gradle/AbstractGroovyTemplatePlugin.groovy @@ -1,6 +1,5 @@ package grails.views.gradle -import grails.util.GrailsNameUtils import groovy.transform.CompileDynamic import groovy.transform.CompileStatic import org.apache.tools.ant.taskdefs.condition.Os @@ -15,8 +14,6 @@ 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 -import org.springframework.boot.gradle.plugin.ResolveMainClassName -import org.springframework.boot.gradle.plugin.SpringBootPlugin /** * Abstract implementation of a plugin that compiles views @@ -75,14 +72,14 @@ class AbstractGroovyTemplatePlugin implements Plugin { templateCompileTask.packageName.set(project.name) templateCompileTask.setSource(project.file("${project.projectDir}/$pathToSource")) templateCompileTask.dependsOn(tasks.named('classes').get()) - project.plugins.withType(SpringBootPlugin).configureEach {plugin -> + project.plugins.withId('org.springframework.boot') { tasks.withType(Jar).configureEach { Task task -> if (task.name in ['jar', 'bootJar', 'war', 'bootWar']) { task.dependsOn(templateCompileTask) } } - tasks.withType(ResolveMainClassName).configureEach { - it.dependsOn(templateCompileTask) + tasks.named('resolveMainClassName').configure { Task task -> + task.dependsOn(templateCompileTask) } } project.plugins.withType(IntegrationTestGradlePlugin).configureEach { diff --git a/gradle-plugin/src/main/groovy/grails/views/gradle/GrailsNameUtils.groovy b/gradle-plugin/src/main/groovy/grails/views/gradle/GrailsNameUtils.groovy new file mode 100644 index 000000000..84f764cd2 --- /dev/null +++ b/gradle-plugin/src/main/groovy/grails/views/gradle/GrailsNameUtils.groovy @@ -0,0 +1,59 @@ +package grails.views.gradle + +import groovy.transform.CompileStatic + +/** + * This class is copying some methods from GrailsNameUtils in grails-bootstrap. + * This is done to avoid a dependency on grails-bootstrap. + * GrailsNameUtils in grails-bootstrap is probably a candidate for moving to a future "grails-common" module. + */ +@CompileStatic +class GrailsNameUtils { + + /** + * Returns the class name for the given logical name and trailing name. For example "person" and "Controller" would evaluate to "PersonController" + * + * @param logicalName The logical name + * @param trailingName The trailing name + * @return The class name + */ + static String getClassName(String logicalName, String trailingName) { + if (isBlank(logicalName)) { + throw new IllegalArgumentException('Argument [logicalName] cannot be null or blank'); + } + + String className = logicalName.substring(0,1).toUpperCase(Locale.ENGLISH) + logicalName.substring(1); + if (trailingName != null) { + className = className + trailingName; + } + return className; + } + + /** + * Return the class name for the given logical name. For example "person" would evaluate to "Person" + * + * @param logicalName The logical name + * @return The class name + */ + static String getClassName(String logicalName) { + return getClassName(logicalName, ''); + } + + /** + *

Determines whether a given string is null, empty, + * or only contains whitespace. If it contains anything other than + * whitespace then the string is not considered to be blank and the + * method returns false.

+ *

We could use Commons Lang for this, but we don't want GrailsNameUtils + * to have a dependency on any external library to minimise the number of + * dependencies required to bootstrap Grails.

+ * @param str The string to test. + * @return true if the string is null, or + * blank. + */ + static boolean isBlank(String str) { + return str == null || str.trim().isEmpty(); + } + +} +