Skip to content

Commit e4cbd67

Browse files
committed
Use SDK man defined Gradle if installed. Fixes #10207
1 parent a0bbaf0 commit e4cbd67

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

grails-shell/src/main/groovy/org/grails/cli/gradle/GradleUtil.groovy

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,21 @@ class GradleUtil {
4343
private static final boolean DEFAULT_SUPPRESS_OUTPUT = true
4444

4545
public static ProjectConnection openGradleConnection(File baseDir) {
46-
DefaultGradleConnector gradleConnector = (DefaultGradleConnector)GradleConnector.newConnector().forProjectDirectory(baseDir)
46+
GradleConnector gradleConnector = GradleConnector.newConnector().forProjectDirectory(baseDir)
4747
if (System.getenv("GRAILS_GRADLE_HOME")) {
4848
gradleConnector.useInstallation(new File(System.getenv("GRAILS_GRADLE_HOME")))
4949
}
50+
else {
51+
def userHome = System.getProperty("user.home")
52+
if(userHome) {
53+
File sdkManGradle = new File("$userHome/.sdkman/candidates/gradle/current")
54+
if(sdkManGradle.exists()) {
55+
gradleConnector.useInstallation(sdkManGradle)
56+
}
57+
}
58+
}
5059

51-
gradleConnector.embedded(!Environment.isInteractiveMode())
52-
.connect()
60+
gradleConnector.connect()
5361
}
5462

5563
public static <T> T withProjectConnection(File baseDir, boolean suppressOutput = DEFAULT_SUPPRESS_OUTPUT,

grails-shell/src/main/groovy/org/grails/cli/gradle/cache/CachedGradleOperation.groovy

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import org.gradle.tooling.GradleConnector
2121
import org.gradle.tooling.ProjectConnection
2222
import org.gradle.tooling.internal.consumer.ConnectorServices
2323
import org.gradle.tooling.internal.consumer.DefaultGradleConnector
24+
import org.grails.cli.gradle.GradleUtil
2425
import org.grails.cli.profile.ProjectContext
2526

2627
import java.util.concurrent.Callable
@@ -64,10 +65,7 @@ abstract class CachedGradleOperation<T> implements Callable<T> {
6465
}
6566

6667
try {
67-
GradleConnector dgc = (GradleConnector)GradleConnector.newConnector()
68-
.forProjectDirectory(projectContext.baseDir)
69-
70-
def projectConnection = dgc.connect()
68+
ProjectConnection projectConnection = GradleUtil.openGradleConnection(projectContext.baseDir)
7169
try {
7270
updateStatusMessage()
7371
def data = readFromGradle(projectConnection)

0 commit comments

Comments
 (0)