简体   繁体   English

gradle设置外部类路径

[英]gradle set external classpath

I'd like to share the classpath created by gradle with an external application (VIM) by exporting the classpath to $CLASSPATH. 我想通过将classpath导出到$ CLASSPATH来与外部应用程序(VIM)共享gradle创建的classpath。 I've tried doing this in the shell via calling gradle and setting the variable but there is a bunch of extra output that makes this cumbersome. 我尝试通过调用gradle和设置变量在shell中执行此操作,但是有很多额外的输出使此操作变得麻烦。 I've also looked at shelling commands via the gradle script but this seems to create a new shell instance and therefore doesn't affect env variables of the current shell. 我也通过gradle脚本查看了shell命令,但这似乎创建了一个新的shell实例,因此不会影响当前shell的env变量。

Does anyone have any experience accomplishing this? 有没有人有完成此工作的经验? Thanks for the help! 谢谢您的帮助!

I think an example would help to clarify: 我认为一个例子将有助于澄清:

task classpath {
    classpathcmd = "export CLASSPATH=" + sourceSets.test.runtimeClasspath.asPath
    // Prints too much extra text
    println classpathcmd
    // Executes command in another shell instance so the variable is "lost"
    exec {
        executable = "sh"
        args = classpathcmd
    }
    // Stracktrace because of file not found exception
    exec {
        commandLine classpathcmd
    }
 }

您可以为此编写一个任务并调用它(可能使用--quiet ),也可以使用Gradle工具API(可能来自vim插件)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM