@@ -7,8 +7,10 @@ import org.apache.tools.ant.taskdefs.condition.Os
7
7
import org.gradle.api.Plugin
8
8
import org.gradle.api.Project
9
9
import org.gradle.api.Task
10
+ import org.gradle.api.file.ConfigurableFileCollection
10
11
import org.gradle.api.file.FileCollection
11
12
import org.gradle.api.tasks.SourceSetOutput
13
+ import org.gradle.api.tasks.TaskContainer
12
14
import org.gradle.api.tasks.bundling.Jar
13
15
import org.grails.gradle.plugin.core.GrailsExtension
14
16
import org.grails.gradle.plugin.core.IntegrationTestGradlePlugin
@@ -32,7 +34,7 @@ class AbstractGroovyTemplatePlugin implements Plugin<Project> {
32
34
AbstractGroovyTemplatePlugin (Class<? extends AbstractGroovyTemplateCompileTask > taskClass , String fileExtension ) {
33
35
this . taskClass = taskClass
34
36
this . fileExtension = fileExtension
35
- this . pathToSource = " grails-app/views"
37
+ this . pathToSource = ' grails-app/views'
36
38
}
37
39
38
40
AbstractGroovyTemplatePlugin (Class<? extends AbstractGroovyTemplateCompileTask > taskClass , String fileExtension , String pathToSource ) {
@@ -43,43 +45,58 @@ class AbstractGroovyTemplatePlugin implements Plugin<Project> {
43
45
44
46
@Override
45
47
void apply (Project project ) {
46
- def allTasks = project. tasks
47
- def upperCaseName = GrailsNameUtils . getClassName(fileExtension)
48
- AbstractGroovyTemplateCompileTask templateCompileTask = (AbstractGroovyTemplateCompileTask ) allTasks. register(" compile${ upperCaseName} Views" . toString(), (Class<? extends Task > ) taskClass). get()
48
+ TaskContainer tasks = project. tasks
49
+ String upperCaseName = GrailsNameUtils . getClassName(fileExtension)
50
+ AbstractGroovyTemplateCompileTask templateCompileTask = (AbstractGroovyTemplateCompileTask ) tasks. register(
51
+ " compile${ upperCaseName} Views" . toString(),
52
+ (Class<? extends Task > ) taskClass
53
+ ). get()
49
54
SourceSetOutput output = SourceSets . findMainSourceSet(project)?. output
50
55
FileCollection classesDir = resolveClassesDirs(output, project)
51
- File destDir = new File (project. buildDir , " ${ templateCompileTask.fileExtension} -classes/main" )
56
+ File destDir = new File (project. layout . buildDirectory . get() . asFile , " ${ templateCompileTask.fileExtension.get() } -classes/main" )
52
57
output?. dir(destDir)
53
58
project. afterEvaluate {
54
59
GrailsExtension grailsExt = project. extensions. getByType(GrailsExtension )
55
60
if (grailsExt. pathingJar && Os . isFamily(Os . FAMILY_WINDOWS )) {
56
- Jar pathingJar = (Jar ) allTasks. named(' pathingJar' ). get()
57
- def allClasspath = project. files(" ${ project.buildDir} /classes/groovy/main" , " ${ project.buildDir} /resources/main" , " ${ project.projectDir} /gsp-classes" , pathingJar. archiveFile. get(). asFile)
61
+ Jar pathingJar = (Jar ) tasks. named(' pathingJar' ). get()
62
+ ConfigurableFileCollection allClasspath = project. files(
63
+ " ${ project.layout.buildDirectory.get().asFile} /classes/groovy/main" ,
64
+ " ${ project.layout.buildDirectory.get().asFile} /resources/main" ,
65
+ " ${ project.layout.projectDirectory.getAsFile()} /gsp-classes" ,
66
+ pathingJar. archiveFile. get(). asFile
67
+ )
58
68
templateCompileTask. dependsOn(pathingJar)
59
69
templateCompileTask. classpath = allClasspath
60
70
}
61
71
}
62
72
def allClasspath = classesDir + project. configurations. named(' compileClasspath' ). get()
63
- templateCompileTask. getDestinationDirectory() . set( destDir )
73
+ templateCompileTask. destinationDirectory . set(destDir)
64
74
templateCompileTask. classpath = allClasspath
65
75
templateCompileTask. packageName. set(project. name)
66
76
templateCompileTask. setSource(project. file(" ${ project.projectDir} /$pathToSource " ))
67
- templateCompileTask. dependsOn( allTasks . named(' classes' ). get() )
77
+ templateCompileTask. dependsOn(tasks . named(' classes' ). get())
68
78
project. plugins. withType(SpringBootPlugin ). configureEach {plugin ->
69
- allTasks. withType(Jar ). configureEach { Task task ->
70
- if (task. name in [' jar' , ' bootJar' , ' war' , ' bootWar' ]) { task. dependsOn templateCompileTask }
79
+ tasks. withType(Jar ). configureEach { Task task ->
80
+ if (task. name in [' jar' , ' bootJar' , ' war' , ' bootWar' ]) {
81
+ task. dependsOn(templateCompileTask)
82
+ }
83
+ }
84
+ tasks. withType(ResolveMainClassName ). configureEach {
85
+ it. dependsOn(templateCompileTask)
71
86
}
72
- allTasks. withType(ResolveMainClassName ). configureEach { t -> t. dependsOn(templateCompileTask)}
73
87
}
74
- project. plugins. withType(IntegrationTestGradlePlugin ). configureEach { plugin ->
75
- allTasks. named(" compileIntegrationTestGroovy" ) { t -> t. dependsOn(templateCompileTask)}
76
- allTasks. named(" integrationTest" ) {t -> t. dependsOn(templateCompileTask)}
88
+ project. plugins. withType(IntegrationTestGradlePlugin ). configureEach {
89
+ tasks. named(' compileIntegrationTestGroovy' ) { Task task ->
90
+ task. dependsOn(templateCompileTask)
91
+ }
92
+ tasks. named(' integrationTest' ) { Task task ->
93
+ task. dependsOn(templateCompileTask)
94
+ }
77
95
}
78
96
}
79
97
80
98
@CompileDynamic
81
99
protected FileCollection resolveClassesDirs (SourceSetOutput output , Project project ) {
82
- return output. classesDirs ?: project. files(new File (project. buildDir, " classes/groovy/main" ))
100
+ return output. classesDirs ?: project. files(new File (project. layout . buildDirectory . get() . asFile, ' classes/groovy/main' ))
83
101
}
84
-
85
102
}
0 commit comments