这就是问题:我想从运行时配置中执行一些带有一些依赖关系的java类。怎么办呢?
task runJava(type: JavaExec, dependsOn:[classes]) {
main = 'mypackage.MyClass'
classpath = //what should I write here to provide classes from runtime configuration?
}
答案 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
。