diff --git a/build.gradle b/build.gradle index a874db2a..dfd59c96 100644 --- a/build.gradle +++ b/build.gradle @@ -75,6 +75,8 @@ java { } dependencies { + implementation platform("org.grails:grails-bom:$grailsVersion") + // compile grails-gradle-plugin with the Groovy version provided by Gradle // to ensure build compatibility with Gradle, currently Groovy 3.0.x // see: https://docs.gradle.org/current/userguide/compatibility.html#groovy 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 87fa60ea..890f91b7 100644 --- a/src/main/groovy/org/grails/gradle/plugin/core/GrailsExtension.groovy +++ b/src/main/groovy/org/grails/gradle/plugin/core/GrailsExtension.groovy @@ -60,7 +60,7 @@ class GrailsExtension { /** * Whether java.time.* package should be a default import package */ - boolean importJavaTime = true + boolean importJavaTime = false /** * 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 c15240c9..0606bfb5 100644 --- a/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy +++ b/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy @@ -143,6 +143,16 @@ class GrailsGradlePlugin extends GroovyPlugin { configureRunCommand(project) configurePathingJar(project) + + def configScriptTask = project.tasks.create('configScript') + def configFile = project.layout.buildDirectory.file('config.groovy') + configScriptTask.outputs.file(configFile) + addJavaTimeImport(project, configScriptTask) + + project.tasks.withType(GroovyCompile).configureEach { GroovyCompile task -> + task.dependsOn('configScript') + task.groovyOptions.configurationScript = project.tasks.named('configScript').get().outputs.files.singleFile + } } protected void excludeDependencies(Project project) { @@ -289,26 +299,19 @@ class GrailsGradlePlugin extends GroovyPlugin { } } } + } - GrailsExtension grailsExt = project.extensions.getByType(GrailsExtension) - project.tasks.withType(GroovyCompile).configureEach { groovyCompileTask -> + protected void addJavaTimeImport(Project project, Task configScriptTask) { + configScriptTask.doLast { + GrailsExtension grailsExt = project.extensions.getByType(GrailsExtension) 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 - } + outputs.files.singleFile << ''' + configuration.with { + def importCustomizer = new org.codehaus.groovy.control.customizers.ImportCustomizer() + importCustomizer.addStarImports('java.time') + addCompilationCustomizers(importCustomizer) } + '''.stripIndent(16) } } } diff --git a/src/main/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePlugin.groovy b/src/main/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePlugin.groovy index 90aa0b66..992c87fb 100644 --- a/src/main/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePlugin.groovy +++ b/src/main/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePlugin.groovy @@ -256,32 +256,22 @@ class GrailsPluginGradlePlugin extends GrailsGradlePlugin { } } - @CompileDynamic protected void configureProjectNameAndVersionASTMetadata(Project project) { - def configScriptTask = project.tasks.create('configScript') - - def configFile = project.file("$project.buildDir/config.groovy") - configScriptTask.outputs.file(configFile) - def projectName = project.name def projectVersion = project.version + def configScriptTask = project.tasks.named('configScript').get() configScriptTask.inputs.property('name', projectName) configScriptTask.inputs.property('version', projectVersion) configScriptTask.doLast { - configFile.parentFile.mkdirs() - configFile.text = """ -withConfig(configuration) { - inline(phase: 'CONVERSION') { source, context, classNode -> - classNode.putNodeMetaData('projectVersion', '$projectVersion') - classNode.putNodeMetaData('projectName', '$projectName') - classNode.putNodeMetaData('isPlugin', 'true') - } -} -""" - } - project.tasks.getByName('compileGroovy').dependsOn(configScriptTask) - project.compileGroovy { - groovyOptions.configurationScript = configFile + outputs.files.singleFile << """ + withConfig(configuration) { + inline(phase: 'CONVERSION') { source, context, classNode -> + classNode.putNodeMetaData('projectVersion', '$projectVersion') + classNode.putNodeMetaData('projectName', '$projectName') + classNode.putNodeMetaData('isPlugin', 'true') + } + } + """.stripIndent(12) } }