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

Default import of java.time.* #346

Merged
merged 7 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -43,6 +43,11 @@ class GrailsExtension {
*/
boolean pathingJar = false

/**
* Whether java.time.* package should be a default import package
*/
boolean javaTime = true
codeconsole marked this conversation as resolved.
Show resolved Hide resolved

/**
* Configure the reloading agent
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,28 @@ class GrailsGradlePlugin extends GroovyPlugin {
}
}
}

GrailsExtension grailsExt = project.extensions.getByType(GrailsExtension)
project.tasks.withType(GroovyCompile).configureEach { groovyCompileTask ->
if (grailsExt.javaTime) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class GroovyPagePlugin implements Plugin<Project> {
}
}


compileGroovyPages.dependsOn( allTasks.findByName("classes") )
compileGroovyPages.dependsOn( compileWebappGroovyPages )

Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/GrailsCompilerConfig.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import org.codehaus.groovy.control.customizers.ImportCustomizer

def importCustomizer = new ImportCustomizer()
importCustomizer.addStarImports('java.time')

configuration.addCompilationCustomizers(importCustomizer)
Loading