Skip to content

Commit

Permalink
Select Groovy version at runtime #231
Browse files Browse the repository at this point in the history
  • Loading branch information
f4lco committed Jul 13, 2021
1 parent 32ad271 commit 5411e91
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ package org.akhikhl.gretty
import groovy.transform.CompileStatic
import groovy.transform.TypeCheckingMode
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.internal.artifacts.dsl.dependencies.DependencyFactory
import org.gradle.process.JavaExecSpec
import org.gradle.tooling.GradleConnector
import org.gradle.tooling.ProjectConnection
Expand All @@ -31,10 +33,20 @@ class DefaultLauncher extends LauncherBase {

static Collection<URL> getRunnerClassPath(Project project, ServerConfig sconfig) {
def files = project.configurations.grettyNoSpringBoot.files +
project.configurations[ServletContainerConfig.getConfig(sconfig.servletContainer).servletContainerRunnerConfig].files
project.configurations[ServletContainerConfig.getConfig(sconfig.servletContainer).servletContainerRunnerConfig].files +
getCurrentGroovy(project)
(files.collect { it.toURI().toURL() }) as LinkedHashSet
}

// #231 If we decide to drop Gradle 6 / Groovy 2 support, we can drop choosing Groovy versions at runtime again.
static Configuration getCurrentGroovy(Project project) {
project.configurations.detachedConfiguration(
project.dependencies.create(DependencyFactory.ClassPathNotation.LOCAL_GROOVY),
project.dependencies.create("org.codehaus.groovy:groovy-cli-commons:${GroovySystem.version}"),
project.dependencies.create("org.codehaus.groovy:groovy-json:${GroovySystem.version}"),
)
}

private Collection<URL> runnerClasspath
protected Project project

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ class ServletContainerConfig {
project.dependencies.add 'runtimeOnly', "org.gretty:gretty-filter:${project.ext.grettyVersion}", {
exclude group: 'javax.servlet', module: 'servlet-api'
}

// #231 If we decide to drop Gradle 6 support / Groovy 2 support, we can drop choosing Groovy versions at runtime again.
// Fingers crossed that users of gretty-filter update Gradle and Groovy versions in tandem.
// Likely, building a Groovy 2 project with a build system of Gradle 7 / Groovy 3 would not work
// because below drags in the wrong versions.
project.dependencies.add("runtimeOnly", "org.codehaus.groovy:groovy-jmx:${GroovySystem.version}")
project.dependencies.add("runtimeOnly", "org.codehaus.groovy:groovy-servlet:${GroovySystem.version}")
alteredDependencies = true
}
}
Expand Down

0 comments on commit 5411e91

Please sign in to comment.