This plugin is broken starting with gradle 2.13, and I currently have no time to fix the issues.
If you like to have a REPL, an alternative is to explicitly create one as part of your project, see docs
This plugin provides gradle tasks that start an interactive groovy shells (also known as REPL), based on
the 'groovysh' command that ships with any Groovy version.
The main feature is an Application shell, meaning a shell where your application
classes (Java or other JVM language) can be imported, instantiated and run. This allows you to interact
directly with your database-layer, service layer, running application, etc. without having to
change a line of your code.
There is also build shell, which allows to connect to a gradle project using the gradle tooling API to run builds.
Another particular feature is a build development shell that has a variable project which represents
your gradle project, allowing you to introspect your project after it has been instantiated. This can be useful
for developing custom gradle plugins, or debugging large setups.
This plugin is Work In Progress, expect some rough edges, but please do report troubles you face.
Note: With version 0.x.x of this plugin, the plugin id was just 'groovysh', so you would have
to write apply plugin: 'groovysh'. This was changed in line with the gradle portal.
The plugin id has changed with version 1.0.0 due to the requirements of gradle-portal.
Currently your project needs to also have the java plugin applied for the shell task:
apply plugin: 'java'
Configuring the Plugin
No configuration is required. To change the defaults, see Configuration
If you encounter groovy version mismatches, explicitly set your system version (until I find a clean way to fix this).
groovysh {
// groovyVersion determines the features of the shell and buildShell tasks.
groovyVersion ='2.4.4'
}
Using the Plugin
Invoke either shell task with option -q (this means "quiet", else the common gradle output will get in the way).
If you have the gradle daemon configured, also add --no-daemon
Note that before running the shell, your project will be build first (compileJava task), which may also mean
downloading its dependencies, so it can take a while for the shell to appear.
Some things you can do with the shell
Instantiate a Spring Container (provided you add Spring dependencies to your project)
Instantiate a Database connection, write business entities etc.
Notice that the Groovy version for the build shell is the same as for gradle (1.8.6), whereas for the application
shell a much more recent version of Groovy (2.3.x) can be used. As a consequence the application shell is much prettier,
and the allowed syntax is different.
Also if you are new to groovysh, the number one quirk to know is that you must not declare variables, e.g.:
groovy:000>def x =3===>3groovy:000> x
Unknownproperty: x
groovy:000> x =3===>3groovy:000> x
===>3
Gradle project lock
While a shell is running that was started from a project, gradle may lock the project,
and other tools may not work well during that time (e.g. IntelliJ gradle update).
Stopping the shell frees the lock again.
The gradle progress logging gets in the way of the output else, no API exists to remove that (see GRADLE-1147).
My Unix prompt does not work after program exit, typed text remains invisible.
This is known to happen with jline1.12. Run reset in that shell as workaround.
How does this compare to the Java 9 'JShell' REPL (Project Kulla)?
Both are REPLs, both can interact with java classes, so usage should be similar. There are no dependencies. Arguably typing Groovy code in a REPL allows for easier interaction.
I get: Cannot resolve external dependency jline:jline:2.11 because no repositories are defined.
This means you need to define some plain repositories (not buildscript repositories):
请发表评论