-
Notifications
You must be signed in to change notification settings - Fork 1
/
groovysh-task.gradle
52 lines (49 loc) · 2.28 KB
/
groovysh-task.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
50
51
52
gradle.projectsLoaded {
rootProject {
afterEvaluate { project ->
if (!project.repositories.any { it.name == 'MavenRepo' }) {
project.repositories {
// To be able to load org.apache.groovy:groovy-groovysh and dependencies
mavenCentral {
content {
includeGroup 'org.apache.groovy'
includeGroup 'jline'
includeGroup 'com.github.javaparser'
includeGroup 'org.ow2.asm'
includeGroup 'org.abego.treelayout'
includeGroup 'org.apache.ivy'
}
}
}
}
project.configurations {
groovyshdependencies
}
project.dependencies {
groovyshdependencies 'org.apache.groovy:groovy-groovysh:4.0.24'
}
project.tasks.register('groovysh') {
group 'debug'
description 'Runs an interactive shell in the context of the project. Use :inspect command to inspect project, gradle, settings or other objects.'
doLast {
URLClassLoader groovyshClassLoader = new URLClassLoader()
configurations.groovyshdependencies.each { File file ->
groovyshClassLoader.addURL(file.toURI().toURL())
}
def groovyshClass
def groovyShell
groovyshClass = Class.forName('org.apache.groovy.groovysh.Groovysh', true, groovyshClassLoader)
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('# Available objects: gradle, settings, project\n# Try :inspect project')
}
}
}
}
}
}
}