gradlewar在使用';configurations.runtime.asPath';在自定义任务中
使用gradle 1.10,我面临无法解释的行为: 设置。渐变:gradlewar在使用';configurations.runtime.asPath';在自定义任务中,gradle,Gradle,使用gradle 1.10,我面临无法解释的行为: 设置。渐变: include('lib1', 'lib2', 'web') subprojects { apply plugin: 'java' } project(':web') { apply plugin: 'war' dependencies { compile project(':lib1') } task myTask(type: JavaExec, dependsOn: 'compileJava'
include('lib1', 'lib2', 'web')
subprojects {
apply plugin: 'java'
}
project(':web') {
apply plugin: 'war'
dependencies {
compile project(':lib1')
}
task myTask(type: JavaExec, dependsOn: 'compileJava') {
main = "some.thirdparty.Class"
args "--searchPath", configurations.runtime.asPath
}
}
project(':lib1') {
dependencies {
compile project(':lib2')
}
}
project(':lib2') {
}
build.gradle:
include('lib1', 'lib2', 'web')
subprojects {
apply plugin: 'java'
}
project(':web') {
apply plugin: 'war'
dependencies {
compile project(':lib1')
}
task myTask(type: JavaExec, dependsOn: 'compileJava') {
main = "some.thirdparty.Class"
args "--searchPath", configurations.runtime.asPath
}
}
project(':lib1') {
dependencies {
compile project(':lib2')
}
}
project(':lib2') {
}
当我运行gradlecleanwar
时,我只有war/build/libs/web.war/web-INF/lib
中的lib1.jar
要使WEB-INF/lib
同时包含lib1.jar
和lib2.jar
,我必须:
- 将
块移到文件末尾project('web')
- 将
更新为configurations.runtime.asPath
(但我需要提供类路径作为路径,因此它不是解决方案)configurations.runtime
为什么会这样?那么,在JavaExec任务中提供模块运行时类路径作为路径的好解决方案是什么呢?
asPath
解析配置,但只有在执行时而不是配置时(特别是在存在项目依赖项的情况下)解析才会正确工作。尝试用doFirst{…}
包装args
行