在开发过程中,我在build.gradle中使用了标准功能的installDist
(来自application
插件):
installDist{}
...但是我现在想执行另一个任务,该任务将“生产”版本安装/分发/部署到生产位置,该版本还将该版本合并到目录结构中。我尝试了这个:
task deployOperativeVersion( type: installDist ) {
destinationDir = file( "$productionDir/$version" )
}
构建失败输出:
Build file '/home/mike/IdeaProjects/JavaFXExp2/Organiser/build.gradle' line: 98
* What went wrong:
A problem occurred evaluating root project 'Organiser'.
> class org.gradle.api.tasks.Sync_Decorated cannot be cast to class java.lang.Class
(org.gradle.api.tasks.Sync_Decorated is in unnamed module of loader org.gradle.
internal.classloader.VisitableURLClassLoader @aec6354; java.lang.Class is in module
java.base of loader 'bootstrap')
看来
installDist
不是Test
中的“类型”。我该如何实现?顺便说一句,我真的很热衷于执行两个单独的任务:运行
installDist
我发现您只需要键入./gradlew inst
...就可以使用一个名为deployXXX
的任务来键入./gradlew depl
就足够了。我也尝试过这个:
task deployOperativeVersion{
installDist{
destinationDir = file( "$operativeDir/$version" )
}
}
...似乎什么也没做。也没有:
task deployOperativeVersion{
doFirst {
installDist {
destinationDir = file("$operativeDir/$version")
}
}
}
过了一会儿,我以为我确实找到了答案:
task deployOperativeVersion{
dependsOn installDist{ destinationDir=file("$productionDir/$version")
}
...但令我惊讶的是(在 hell 冻结之前我是否会对Gradle有了一个合理的了解?),其中包括实际上似乎在影响“常规”
installDist
任务:具体地说,它阻止了后者正常运行,并且意味着即使我运行installDist
,部署/分发/安装仍然会转到productionDir/version
,而不是默认位置。因此,我想知道两个任务都依赖于
installDist
:task deployOperativeVersion{
dependsOn installDist{ destinationDir=file("$productionDir/$version") }
}
task stdInstall{
dependsOn installDist{ destinationDir=file("build/install") }
}
……哈哈,不高兴:我跑了一个,部署成功了。然后我运行另一个...并得到一个错误:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':installDist'.
> The specified installation directory '/home/mike/IdeaProjects/JavaFXExp2/Organiser/build/install' is neither empty nor does it contain an installation for 'Organiser'.
If you really want to install to this directory, delete it and run the install task again.
Alternatively, choose a different installation directory.
...不用说,事实并非如此:在... Organiser / build / install下只有一个目录Organizer,在其下有/ bin和/ lib目录。
最佳答案
您的任务应声明为Sync
任务,这是installDist
任务的实际类型。 application
插件正在使用distribution
插件。您可以从作为源的main
发行版或installDist
任务中获取内容配置。
task deployOperativeVersion(type: Sync) {
destinationDir = file("${productionDir}/${version}")
with distributions.main.content
}
要么
task deployOperativeVersion(type: Sync) {
destinationDir = file("${productionDir}/${version}")
with installDist
}
关于gradle - 创建第二个installDist任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61122363/