diff --git a/src/main/groovy/org/grails/gradle/plugin/core/GrailsExtension.groovy b/src/main/groovy/org/grails/gradle/plugin/core/GrailsExtension.groovy index 90e62037..71508746 100644 --- a/src/main/groovy/org/grails/gradle/plugin/core/GrailsExtension.groovy +++ b/src/main/groovy/org/grails/gradle/plugin/core/GrailsExtension.groovy @@ -43,6 +43,11 @@ class GrailsExtension { */ boolean pathingJar = false + /** + * Whether java.time.* package should be a default import package + */ + boolean importJavaTime = true + /** * Configure the reloading agent */ diff --git a/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy b/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy index db1ae17e..93885a7b 100644 --- a/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy +++ b/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy @@ -289,6 +289,28 @@ class GrailsGradlePlugin extends GroovyPlugin { } } } + + GrailsExtension grailsExt = project.extensions.getByType(GrailsExtension) + project.tasks.withType(GroovyCompile).configureEach { groovyCompileTask -> + if (grailsExt.importJavaTime) { + groovyCompileTask.doFirst { + def configScriptStream = getClass().getResourceAsStream("/GrailsCompilerConfig.groovy") + if (configScriptStream != null) { + def tempConfigScriptFile = File.createTempFile("build/GrailsCompilerConfig", ".groovy") + tempConfigScriptFile.mkdirs() + tempConfigScriptFile.deleteOnExit() + + def existingScript = groovyCompileTask.groovyOptions.configurationScript + if (existingScript) { + tempConfigScriptFile << existingScript.text + } + + tempConfigScriptFile.text = configScriptStream.text + groovyCompileTask.groovyOptions.configurationScript = tempConfigScriptFile + } + } + } + } } @CompileStatic diff --git a/src/main/groovy/org/grails/gradle/plugin/web/gsp/GroovyPagePlugin.groovy b/src/main/groovy/org/grails/gradle/plugin/web/gsp/GroovyPagePlugin.groovy index 28873957..8b60e656 100644 --- a/src/main/groovy/org/grails/gradle/plugin/web/gsp/GroovyPagePlugin.groovy +++ b/src/main/groovy/org/grails/gradle/plugin/web/gsp/GroovyPagePlugin.groovy @@ -80,7 +80,6 @@ class GroovyPagePlugin implements Plugin { } } - compileGroovyPages.dependsOn( allTasks.findByName("classes") ) compileGroovyPages.dependsOn( compileWebappGroovyPages ) diff --git a/src/main/resources/GrailsCompilerConfig.groovy b/src/main/resources/GrailsCompilerConfig.groovy new file mode 100644 index 00000000..c1a4c6ee --- /dev/null +++ b/src/main/resources/GrailsCompilerConfig.groovy @@ -0,0 +1,6 @@ +import org.codehaus.groovy.control.customizers.ImportCustomizer + +def importCustomizer = new ImportCustomizer() +importCustomizer.addStarImports('java.time') + +configuration.addCompilationCustomizers(importCustomizer)