我面对的行为是我无法解释的,使用gradle 1.10我有:
settings.gradle:
include('lib1', 'lib2', 'web')
的build.gradle:
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') {
}
当我运行gradle clean war
时,lib1.jar
中只有war/build/libs/web.war/WEB-INF/lib
。
要使WEB-INF/lib
同时包含lib1.jar
和lib2.jar
,我必须:
project('web')
块移至文件末尾configurations.runtime.asPath
更新为configurations.runtime
(但我需要提供类路径作为路径,因此它不是解决方案)我阅读了build lifecycle说明,试图比较--debug输出,但这没有帮助。
为什么会这样?在JavaExec任务中将模块运行时类路径作为路径提供什么是一个很好的解决方案呢?
答案 0 :(得分:2)
asPath
解析配置,但解决方案只有在执行时而不是配置时发生(特别是在存在项目依赖性时)才能正常工作。尝试用args
包裹doFirst { ... }
行。