Gradle:如何使JavaExec任务使用配置类路径? [英] Gradle: how to make JavaExec task use configuration classpath?

查看:73
本文介绍了Gradle:如何使JavaExec任务使用配置类路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是问题所在:我想执行一些Java类,这些类具有一些来自运行时配置的依赖项.该怎么办?

Here's the problem: I want to execute some java class with some dependencies from, say, runtime configuration. How can this be done?

task runJava(type: JavaExec, dependsOn:[classes]) {
        main = 'mypackage.MyClass'
        classpath = //what should I write here to provide classes from runtime configuration?
}

推荐答案

您可能希望使用

You will probably want to use the runtime classpath of your Source sets which includes the compiled classes of your project as well as all the runtime dependencies.

task runJava(type: JavaExec, dependsOn:[classes]) {
    main = 'mypackage.MyClass'
    classpath = sourceSets.main.runtimeClasspath
}

如果要获取特定配置的路径,可以执行以下操作: configurations.getByName('runtime').asPath 或更短的 configurations.runtime.asPath.

In case you want to the get the path of a specific configuration you can do something like this: configurations.getByName('runtime').asPath or shorter configurations.runtime.asPath.

这篇关于Gradle:如何使JavaExec任务使用配置类路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆