{"id":15563945,"url":"https://github.com/mrsarm/jshell-plugin","last_synced_at":"2025-09-11T07:32:10.360Z","repository":{"id":45145093,"uuid":"252575553","full_name":"mrsarm/jshell-plugin","owner":"mrsarm","description":"Gradle plugin to explore your code and dependencies with in jshell","archived":false,"fork":false,"pushed_at":"2023-02-05T17:10:44.000Z","size":118,"stargazers_count":28,"open_issues_count":2,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-03T22:36:35.247Z","etag":null,"topics":["gradle","gradle-plugin","java","java9","jshell"],"latest_commit_sha":null,"homepage":"https://plugins.gradle.org/plugin/com.github.mrsarm.jshell.plugin","language":"Groovy","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrsarm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-02T22:10:43.000Z","updated_at":"2024-10-27T01:08:30.000Z","dependencies_parsed_at":"2023-02-17T07:16:13.300Z","dependency_job_id":null,"html_url":"https://github.com/mrsarm/jshell-plugin","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/mrsarm/jshell-plugin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrsarm%2Fjshell-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrsarm%2Fjshell-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrsarm%2Fjshell-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrsarm%2Fjshell-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrsarm","download_url":"https://codeload.github.com/mrsarm/jshell-plugin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrsarm%2Fjshell-plugin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274595070,"owners_count":25314015,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-11T02:00:13.660Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gradle","gradle-plugin","java","java9","jshell"],"created_at":"2024-10-02T16:31:59.239Z","updated_at":"2025-09-11T07:32:10.028Z","avatar_url":"https://github.com/mrsarm.png","language":"Groovy","funding_links":[],"categories":[],"sub_categories":[],"readme":"JShell Plugin\n=============\n\n**Gradle plugin** that helps you to explore your code and dependencies in your gradle project\nwith in [jshell](https://docs.oracle.com/javase/9/jshell/introduction-jshell.htm),\nthe official Java REPL tool (Java 9+).\n\nHosted in the **Gradle plugins** site: https://plugins.gradle.org/plugin/com.github.mrsarm.jshell.plugin\n\n\u003e ### :keyboard: Use `rlwrap` to make arrow keys work ([see](#tab-completion-and-arrow-keys-not-working)).\n\n\n - [Getting started](#getting-started)\n - [Startup options](#startup-options)\n - [Spring Boot applications](#spring-boot-applications)\n - [Troubleshooting](#troubleshooting)\n - [System Requirements](#system-requirements)\n - [Build and Publish](#build-and-publish)\n - [About](#about)\n\n\nGetting started\n---------------\n\nTo use this plugin, add the following to your `build.gradle`:\n\n```groovy\nplugins {\n  id \"com.github.mrsarm.jshell.plugin\" version \"1.2.1\"\n}\n```\n\nTask `jshell` is now enabled, which execute the jshell with your classes and\ndependencies after compiling your code.\n\nYou need to run the task `jshell` with the option `--console plain`.\nFollowing is an example:\n\n    $ gradle --console plain jshell\n    \n    ... (gradle tasks output) ...\n    \n    \u003e Task :jshell\n    |  Welcome to JShell -- Version 11.0.6\n    |  For an introduction type: /help intro\n    \n    jshell\u003e println(\"Hello world!\")\n    Hello world!\n    \n    jshell\u003e _\n\n\nStartup options\n---------------\n\nThe shell console starts with the options\n`--startup DEFAULT --startup PRINTING` so always\nthe following imports and functions are available:\n\n - java.io\n - java.math\n - java.net\n - java.nio.file\n - java.util\n - java.util.concurrent\n - java.util.function\n - java.util.prefs\n - java.util.regex\n - java.util.stream\n - print (alias of `System.out.print`)\n - println (alias of `System.out.println`)\n\n### JShell scripts\n\nIf the plugin founds at the root of the project a\n[JShell Script](https://docs.oracle.com/javase/9/jshell/scripts.htm)\nnamed `startup.jsh`, it will append to the JShell session\nthe argument `--startup startup.jsh`, executing\nat the beginning all the instructions in the script,\nso you can add there all the imports, object definitions\nor any Java instruction that you want to execute\nat the beginning of the session.\n\nYou can override the startup script path with the project\nproperty `jshell.startup` in the `gradle.properties` file,\nor set the same property directly in the command line\narguments:\n\n    $ gradle --console plain jshell -Pjshell.startup=/path/to/run.jsh\n\nIf you have a `startup.jsh` script at the root of the project\nbut at some point you don't want to execute it nor any other\nstartup script within the session, just pass the `jshell.startup` property\nwith an empty value: `gradle --console plain jshell -Pjshell.startup=`.\n\n\nSpring Boot applications\n------------------------\n\nThe JShell plugin allows to startup a Spring Boot application\nwithin the console and access to the business object from there,\nbut you will need to do some extra configurations, and add\na dependency to the project to make easier to access\nto the Spring beans.\n\n1. Setup the plugin following the steps in the\n   [Getting started](#getting-started) section.\n\n2. Add the library [spring-ctx](https://github.com/mrsarm/spring-ctx)\n   to your dependencies as follows:\n\n   - Add the following dependency to your `dependencies` section:\n     \n     ```groovy\n     implementation 'com.github.mrsarm:spring-ctx:1.0.0'\n     ```\n\n   - At the end of the `repositories` section:\n\n     ```groovy\n     maven { url 'https://jitpack.io' }\n     ```\n\n3. Any Spring Boot application has a class annotated with\n   `@SpringBootApplication` that is the starting point of\n   the application, with a `public static void main(String[] args)`\n   method, you need to create a [startup.jsh](#startup-options) file\n   at the root of your project calling that method, eg:\n\n   ```java\n   com.my.package.MyApplication.main(new String[]{})\n   ```\n\n   You can also add the imports of the business classes you are going\n   to play with, as many as you have, otherwise you can import them\n   once the JShell started:\n\n   ```java\n   import com.my.package.services.MyUserService\n   ```\n\n4. Done. You can start playing with your Spring application, you can\n   access to the bean objects once the JShell started as\n   following:\n\n   ```\n   $ ./gradlew --console plain jshell\n   \n     .   ____          _            __ _ _\n    /\\\\ / ___'_ __ _ _(_)_ __  __ _ \\ \\ \\ \\\n   ( ( )\\___ | '_ | '_| | '_ \\/ _` | \\ \\ \\ \\\n    \\\\/  ___)| |_)| | | | | || (_| |  ) ) ) )\n     '  |____| .__|_| |_|_| |_\\__, | / / / /\n    =========|_|==============|___/=/_/_/_/\n    :: Spring Boot ::        (v2.2.4.RELEASE)\n   \n   14:43:28.320  INFO com.my.package.MyApplication             : Starting Application on kubu1910 with PID 5225 (/projects/...\n   14:43:28.323 DEBUG com.my.package.MyApplication             : Running with Spring Boot v2.2.4.RELEASE, Spring v5.2.3.RELEASE\n   14:43:28.324  INFO com.my.package.MyApplication             : The following profiles are active: ...\n   14:43:30.229  INFO boot.web.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8010 (http)\n   \n   ...\n   ...\n   \n   14:43:33.729  INFO tuate.endpoint.web.EndpointLinksResolver : Exposing 3 endpoint(s) beneath base path ''\n   14:43:33.811  INFO boot.web.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8010 (http) with context path ''\n   14:43:33.816  INFO com.my.package.MyApplication             : Started Application in 6.995 seconds (JVM running for 10.524)\n   \n   \u003e Task :jshell\n   |  Welcome to JShell -- Version 11.0.6\n   |  For an introduction type: /help intro\n   \n   jshell\u003e var myUserService = ctx.App.getBean(MyUserService.class)\n   \n   jshell\u003e ctx.App.ppjson(myUserService.getByUsername(\"admin\"))\n   {\n     \"name\" : \"Jhon\",\n     \"lastName\" : \"Due\",\n     \"username\" : \"admin\",\n     \"age\" : null\n   }\n   ```\n\n   You can add to the `startup.jsh` not just the call to the `main` method\n   and useful imports, but also adds the bean declarations you are\n   going to use most likely, eg.\n   `var myUserService = ctx.App.getBean(MyUserService.class)`, or any other\n   snippet of Java code that may save you time running each time the JShell.\n\n   The class `ctx.App` comes from the `spring-ctx` dependency added, checkout the\n   [documentation](https://github.com/mrsarm/spring-ctx/blob/master/README.md)\n   of all the useful methods it has to help you to play with\n   the Spring framework.\n\n\nTroubleshooting\n---------------\n\n### JShell warning at startup\n\nIf you see this warning before the jshell console starts:\n\n\u003e :jshell task :classes not found, be sure to compile the project first\n\nMeans the `classes` task needed to compile your project before launch `jshell`\ndoes not exist, just append in the command line the task needed to compile\nthe project. Some times is the same `classes` task but is not detected\nin multi-modules projects, so you need to add it explicitly in the\nGradle command:\n\n    $ gradle --console plain classes jshell\n\nLater if you need to run again the JShell but no change to the\nsource code was performed, you don't need to append the `classes` task,\nalthough the warning will still appear, just ignore it.\n\n### The console is exited once started\n\nCurrently, there is an [issue#1](https://github.com/mrsarm/jshell-plugin/issues/1)\n(and [issue#4](https://github.com/mrsarm/jshell-plugin/issues/4)) that\nthe plugin does not work properly with Java 12 and above, exiting\nthe interactive console as following:\n\n    $ ./gradlew --console plain jshell\n    \u003e Task :compileJava UP-TO-DATE\n    \u003e Task :processResources NO-SOURCE\n    \u003e Task :classes UP-TO-DATE\n    \n    \u003e Task :jshellSetup\n    \n    \u003e Task :jshell\n    |  Welcome to JShell -- Version 12.0.2\n    |  For an introduction type: /help intro\n    \n    BUILD SUCCESSFUL in 1s\n    3 actionable tasks: 2 executed, 1 up-to-date\n\n    $ _\n\nIt's recommended to **use the latest LTS: version 11**, but it works\nwith Java 9 and 10 as well. Previous versions (Java 8, 7...) are not\nsupported because the JShell is not built-in on those versions, but\nif you want to run the JShell with an old project, pay special attention\nto the section bellow.\n\nAlthough if you cannot run with a version bellow to Java 12, you are\nstill able to run [JShell scripts](#jshell-scripts) with the plugin,\nbut once executed the _.jsh_ script the interactive console will exit.\n\n### I have a JDK 9+ installation, but my default JDK is the JDK 8 or below\n\nIn that case Gradle will try to use the default JDK, and `jshell` is\nnot available in Java 8 and above. Moreover the steps to change the\ndefault JDK vary depending of your system, but Gradle use the default\nJDK except if it's defined the `$JAVA_HOME` environment variable,\nso when you enter in a new console where you need to use your Java 9+\ninstallation with Gradle, just export the variable with the path to\nthe JDK installation, eg:\n\n    $ export JAVA_HOME=\"/usr/lib/jvm/java-11-openjdk-amd64\"\n\nThe export will live just whiting the session where is defined,\nit does not change your system configuration globally, and calling\n`unset JAVA_HOME` or opening a new session the export will\nnot have effect anymore.\n\nYou can even create an alias in your `~/.profile` / `~/.bashrc`\nfile like: `alias usejava9='export JAVA_HOME=/System/Library/Java/...'`\nto later switch easily to the other distribution calling\n`usejava9`, or `usejava8` to switch back.\n\nAnother good alternative to install and switch between different\nversions of Java is [SdkMan!](https://sdkman.io/), totally recommended,\nand it also allows to install multiple versions of Gradle, Maven, Kotlin...\nand many Java based tools.\n\n### Gradle output is mixed with the jshell output in the console\n\nIf content like `\u003c-------------\u003e 0% EXECUTING [16s]` is mixed\nin the console with the jshell output each time you try\nto execute something within the jshell console, remember to pass\nthe option `--console plain` to the gradle command, but if\nthe output continues mixed up with Gradle messages, try\nadding the option `--no-daemon` to start up the jshell:\n\n    $ gradle --no-daemon --console plain jshell\n\n### Tab completion and arrow keys not working\n\nAuto-completion does not work, and pressing arrow keys triggers\nweird characters in the console. Unfortunately, with the\ncurrent console support from Gradle, there is no\nsolution for this [bug](https://github.com/mrsarm/jshell-plugin/issues/2).\n\nHowever, the JShell task can be invoked with the command **rlwrap** from the\nconsole to overcome the arrow keys issues:\n\n    $ rlwrap ./gradlew --console plain jshell\n\n`rlwrap` takes care of the arrow keys management and history.\nJust remember to check you have installed it before invoking the JShell with\nthe command the first time.\n\nYou can install [rlwrap](https://github.com/hanslub42/rlwrap) on Windows using\nCygwin or MinGW, and on Linux and MacOS.  For MacOS, consider installing with\nHomebrew: `brew install rlwrap`.\n\nSystem Requirements\n-------------------\n\n * JDK 9+\n * Gradle\n\n\nBuild and Publish\n-----------------\n\n\u003e :information_source: Only for developers that want to make\n\u003e changes to this source code.\n\nTo compile this plugin and build the .jar locally, checkout the\nsource code and execute:\n\n    $ ./gradlew build\n\nThe compilation must be done with the JDK 9 for general release.\n\nPublish to your local Maven repo (normally `~/.m2/repository/`):\n\n    $ ./gradlew publishToMavenLocal\n\nPublish to [plugins.gradle.org](https://plugins.gradle.org/):\n\n    $ ./gradlew publishPlugins\n\nNOTE: Because Java 9 is an old version, the command above might fail in\nthe execution due SSL issues, in that case better to switch to Java 11 to\nexecute only the `publishPlugins` command. With Java 17+ it also fails but\nbecause the plugin performs some validations before send the artifacts, but\nstill the artifacts generated with Java 9 are valid for Java 17+.\n\n### Using from the local repo\n\nTo test local changes published to the local repo with the\n`publishToMavenLocal` task mentioned above, you need\nto add the plugin to the `build.gradle` in the project\nwhere the plugin is tested, in the following manner: \n\n```groovy\nbuildscript {\n  repositories {\n    mavenLocal()\n    maven {\n      url \"https://plugins.gradle.org/m2/\"\n    }\n  }\n  dependencies {\n    classpath \"com.github.mrsarm:jshell-plugin:1.2.1\"\n  }\n}\n\napply plugin: \"com.github.mrsarm.jshell.plugin\"\n```\n\nAlso, when launching the plugin from another project, to see the \":jshell\" logs\nadd the `--info` argument in the command line, e.g.: `gradle --console plain jshell --info`.\n\nAbout\n-----\n\nThis is a fork of the project https://github.com/bitterfox/jshell-gradle-plugin ,\nI forked it because the original project is not receiving patches\nand this version solves some issues and adds the following features:\n\n - It works with **multi-module projects**.\n - There is no need to set the env variable `JAVA_OPTS` with a bunch\n   of arguments _\"--add-exports jdk.jshell/jdk.intern...\"_.\n - It allows to run at the beginning of the session a _.jsh_ startup script.\n - Special support to the **Spring Framework**.\n\n**Project**: https://github.com/mrsarm/jshell-plugin\n\n### Authors\n\n - Mariano Ruiz \u003cmrsarm@gmail.com\u003e\n - https://github.com/bitterfox\n   (original [project](https://github.com/bitterfox/jshell-gradle-plugin))\n\n### License\n\n - (2020-2022) [Apache Software License 2.0](https://www.apache.org/licenses/LICENSE-2.0).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrsarm%2Fjshell-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrsarm%2Fjshell-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrsarm%2Fjshell-plugin/lists"}