是否创建第二个installDist任务?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了是否创建第二个installDist任务?相关的知识,希望对你有一定的参考价值。
在开发过程中,我在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")
...但令我惊讶的是(在地狱冻结之前我是否会对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
以上是关于是否创建第二个installDist任务?的主要内容,如果未能解决你的问题,请参考以下文章