{"id":26265672,"url":"https://github.com/luyiisme/groovy-script-executor","last_synced_at":"2026-05-22T05:06:51.119Z","repository":{"id":55881566,"uuid":"81658053","full_name":"luyiisme/groovy-script-executor","owner":"luyiisme","description":"groovy-script-executor","archived":false,"fork":false,"pushed_at":"2021-02-19T13:36:32.000Z","size":71,"stargazers_count":1,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-07-04T04:35:11.677Z","etag":null,"topics":["groovy","sandbox","script"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/luyiisme.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-11T14:27:18.000Z","updated_at":"2023-07-04T04:35:11.677Z","dependencies_parsed_at":"2022-08-15T08:31:12.886Z","dependency_job_id":null,"html_url":"https://github.com/luyiisme/groovy-script-executor","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luyiisme%2Fgroovy-script-executor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luyiisme%2Fgroovy-script-executor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luyiisme%2Fgroovy-script-executor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luyiisme%2Fgroovy-script-executor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luyiisme","download_url":"https://codeload.github.com/luyiisme/groovy-script-executor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243515559,"owners_count":20303258,"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","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":["groovy","sandbox","script"],"created_at":"2025-03-14T03:14:38.370Z","updated_at":"2026-05-22T05:06:51.065Z","avatar_url":"https://github.com/luyiisme.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 基于Groovy的脚本引擎\n目标：简化 Groovy 作为动态脚本场景的工作\n\n相比直接使用 GroovyShell，我们为脚本场景做了些方便使用的封装。已应用于内部很多项目，这是抽出的一个简化版本。\n\n详细 features:\n- 支持运行时基于 ScriptName 的在内存中登记和更新脚本内容，方便 ScriptName 标识不变情况下做脚本内容修改；\n- 解决常见的容易 FullGC 或 OOM 问题（Groovy 在动态脚本场景，容易因脚本过多对应 class无法正常卸载导致 FullGC的问题，网上该类问题很普遍）;\n- 提供沙箱功能，沙箱的限制控制能力通过拦截器支持，并默认提供一些黑名单的 GroovyInterceptors（\n比如，NoReflectionAllowedInterceptor，NoSystemExitInterceptor），特别限定的场景建议直接使用白名单方式；\n- 提供执行上下文，方便在执行时传递执行参数；\n- 兼容支持JDK 1.6；\n- TODO,提供脚本的 Repository，方便作为个更开箱即用的方案；\n\n# 用法\n\n```\n        //PHASE 1:脚本引擎初始化线程执行\n        ScriptEngine scriptEngine = new GroovyScriptEngine();\n        //沙箱功能的拦截器:（可选，但建议有）\n        scriptEngine.addGroovyInterceptor(new NoSystemExitInterceptor());\n```\n```\n        //PHASE 2:脚本管理线程执行\n        /** \"123\" 作为 scriptName，登记入内存中;\n         * 脚本内容里: context 表示脚本上下文对象,它对应于您在执行时传入参数 map,比如后面,scriptEngine.invoke(\"123\", params)\n         * context.name 执行结果: jack\n         **/\n        ((ScriptManager)scriptEngine).registerScript(\"123\", \"println( context.name ); return 1;\");\n```\n```\n        //PHASE 3:脚本执行线程,实际业务执行调用\n        Map\u003cString, Object\u003e params = new HashMap\u003cString, Object\u003e();\n        params.put(\"name\", \"jack\");\n        Integer v = scriptEngine.invoke(\"123\", params);\n        Assert.assertSame(1, v);\n```\n\n```\n        //PHASE 4:删除内存中所有的脚本\n        ((ScriptManager)scriptEngine).removeAllScript();\n```\n# 依赖引入\npom中依赖\n```\n\u003cdependency\u003e\n  \u003cgroupId\u003eio.github.luyiisme\u003c/groupId\u003e\n  \u003cartifactId\u003egroovy-script-executor\u003c/artifactId\u003e\n  \u003cversion\u003e${latest.version}\u003c/version\u003e\n\u003c/dependency\u003e\n```\n# 最佳实践\n- 使用方可以自己维护个脚本的管理DB表；\n 业务应用启动时或运行时发生脚本更新时 GroovyScriptEngine 同步刷新加载；\n- 引入\"context\" 这个变量是 built-in，方便脚本里使用参数的；\n- GroovyScriptEngine是否需要多个实例，根据每个使用场景的差异性决定；","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluyiisme%2Fgroovy-script-executor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluyiisme%2Fgroovy-script-executor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluyiisme%2Fgroovy-script-executor/lists"}