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

Correctly define dependencies for compileGsonViews #454

Merged
merged 4 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ projectUrl=https://views.grails.org
projectVersion=3.0.0-SNAPSHOT
servletApiVersion=4.0.1
spockVersion=2.1-groovy-3.0
springBootVersion=2.7.12
springDependencyManagementPluginVersion=1.1.0
testingSupportVersion=3.0.0-RC1

Expand Down
1 change: 1 addition & 0 deletions gradle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ repositories {

dependencies {
compileOnly gradleApi()
api "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion"
api "org.grails:grails-gradle-plugin:$grailsGradlePluginVersion"
api "org.codehaus.groovy:groovy:$groovyVersion"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ abstract class AbstractGroovyTemplateCompileTask extends AbstractCompile {
@Override
@CompileDynamic
void execute(JavaExecSpec javaExecSpec) {
javaExecSpec.setMain(getCompilerName())
javaExecSpec.mainClass.set(getCompilerName())
javaExecSpec.setClasspath(getClasspath())

def jvmArgs = compileOptions.forkOptions.jvmArgs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.artifacts.Configuration
import org.gradle.api.file.CopySpec
import org.gradle.api.file.FileCollection
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.SourceSetOutput
import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.bundling.War
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
Expand Down Expand Up @@ -47,30 +48,30 @@ class AbstractGroovyTemplatePlugin implements Plugin<Project> {
def allTasks = project.tasks
def upperCaseName = GrailsNameUtils.getClassName(fileExtension)

AbstractGroovyTemplateCompileTask templateCompileTask = (AbstractGroovyTemplateCompileTask)allTasks.create("compile${upperCaseName}Views".toString(), (Class<? extends Task>)taskClass)
AbstractGroovyTemplateCompileTask templateCompileTask = (AbstractGroovyTemplateCompileTask) allTasks.register("compile${upperCaseName}Views".toString(), (Class<? extends Task>) taskClass).get()


SourceSet mainSourceSet = SourceSets.findMainSourceSet(project)
SourceSetOutput output = mainSourceSet?.output
FileCollection classesDir = resolveClassesDirs(output, project)
File destDir = new File(project.buildDir, "${templateCompileTask.fileExtension}-classes/main")
output?.dir(destDir)
Configuration providedConfig = project.configurations.findByName('provided')
Configuration providedConfig = project.configurations.named('provided').get()


FileCollection allClasspath
FileCollection allClasspath = project.objects.fileCollection()

project.afterEvaluate {
GrailsExtension grailsExt = project.extensions.getByType(GrailsExtension)
if (grailsExt.pathingJar && Os.isFamily(Os.FAMILY_WINDOWS)) {
Jar pathingJar = (Jar) allTasks.findByName('pathingJar')
allClasspath = project.files("${project.buildDir}/classes/groovy/main", "${project.buildDir}/resources/main", "${project.projectDir}/gsp-classes", pathingJar.archivePath)
Jar pathingJar = (Jar) allTasks.named('pathingJar').get()
allClasspath += project.files("${project.buildDir}/classes/groovy/main", "${project.buildDir}/resources/main", "${project.projectDir}/gsp-classes", pathingJar.archiveFile.get().asFile)
templateCompileTask.dependsOn(pathingJar)
templateCompileTask.setClasspath(allClasspath)
}
}

allClasspath = classesDir + project.configurations.getByName('compileClasspath')
allClasspath += classesDir + project.configurations.named('compileClasspath').get()
if(providedConfig) {
allClasspath += providedConfig
}
Expand All @@ -84,11 +85,27 @@ class AbstractGroovyTemplatePlugin implements Plugin<Project> {
project.file("${project.projectDir}/$pathToSource")
)

templateCompileTask.dependsOn( allTasks.findByName('classes') )
templateCompileTask.dependsOn( allTasks.named('classes').get() )

allTasks.withType(Jar) { Jar jar ->
if (jar.name in ['jar', 'bootJar', 'war', 'bootWar']) {
jar.dependsOn templateCompileTask
project.plugins.withType(SpringBootPlugin).configureEach {plugin ->
allTasks.withType(Jar).configureEach { Task task ->
if (task.name in ['jar', 'bootJar', 'war', 'bootWar']) {
task.dependsOn templateCompileTask
}
}

allTasks.withType(ResolveMainClassName)
.configureEach { t ->
t.dependsOn(templateCompileTask)
}
}

project.plugins.withType(IntegrationTestGradlePlugin).configureEach { plugin ->
allTasks.named("compileIntegrationTestGroovy") { t->
t.dependsOn(templateCompileTask)
}
allTasks.named("integrationTest") {t ->
t.dependsOn(templateCompileTask)
}
}
}
Expand Down