Gradle:如何使JavaExec任务使用配置类路径?

时间:2012-12-03 12:48:35

标签: java gradle build-process

这就是问题:我想从运行时配置中执行一些带有一些依赖关系的java类。怎么办呢?

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

1 个答案:

答案 0 :(得分:16)

您可能希望使用Source sets的运行时类路径,其中包含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