-
Notifications
You must be signed in to change notification settings - Fork 1
/
gradle-groovysh-init.gradle
49 lines (44 loc) · 1.94 KB
/
gradle-groovysh-init.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
gradle.projectsLoaded {
rootProject {
afterEvaluate { project ->
if (!project.repositories.any { it.name == 'MavenRepo' }) {
project.repositories {
// To be able to load org.codehaus.groovy:groovy-groovysh
mavenCentral()
}
}
project.configurations {
groovyshdependencies
}
project.dependencies {
groovyshdependencies("org.codehaus.groovy:groovy-groovysh:${GroovySystem.version}") {
exclude group: 'org.codehaus.groovy'
}
}
project.tasks.register('groovysh') {
group 'debug'
description 'Runs an interactive shell in the context of the project.'
doLast {
URLClassLoader groovyObjectClassLoader = GroovyObject.classLoader
def groovyshClass
def groovyShell
// Add dependency jars to classloader
configurations.groovyshdependencies.each { File file ->
groovyObjectClassLoader.addURL(file.toURL())
}
Class.forName('jline.console.history.FileHistory', true, groovyObjectClassLoader)
groovyshClass = Class.forName('org.codehaus.groovy.tools.shell.Groovysh', true, groovyObjectClassLoader)
if (groovyshClass) {
groovyShell = groovyshClass.newInstance()
}
if (groovyShell) {
groovyShell.interp.context.variables.put('gradle', gradle)
groovyShell.interp.context.variables.put('settings', gradle.settings)
groovyShell.interp.context.variables.put('project', project)
groovyShell.run('')
}
}
}
}
}
}