Gradle 是否创建第二个installDist任务?
在开发过程中,我使用build.gradle中的标准函数Gradle 是否创建第二个installDist任务?,gradle,deployment,task,Gradle,Deployment,Task,在开发过程中,我使用build.gradle中的标准函数installDist(来自应用程序插件): installDist{} 。。。但是我现在想有另一个任务,它将安装/分发/部署一个“生产”版本到生产位置,它还将该版本合并到目录结构中。我试过这个: task deployOperativeVersion( type: installDist ) { destinationDir = file( "$productionDir/$version" ) } task deployOp
installDist
(来自应用程序
插件):
installDist{}
。。。但是我现在想有另一个任务,它将安装/分发/部署一个“生产”版本到生产位置,它还将该版本合并到目录结构中。我试过这个:
task deployOperativeVersion( type: installDist ) {
destinationDir = file( "$productionDir/$version" )
}
task deployOperativeVersion{
installDist{
destinationDir = file( "$operativeDir/$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( type: installDist ) {
destinationDir = file( "$productionDir/$version" )
}
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.
。。。不用说,情况并非如此:在…Organizer/build/install下只有一个目录Organizer,其下有/bin和/lib目录。您的任务应声明为
Sync
任务,这是installDist
任务的实际类型。应用程序
插件正在使用发行版
插件。您可以从作为源的main
发行版或installDist
任务中获取内容配置
task deployOperativeVersion(type: Sync) {
destinationDir = file("${productionDir}/${version}")
with distributions.main.content
}
或
非常感谢。我在找到了应用程序插件的API文档。但是你能告诉我这个
和的东西在哪里被记录下来吗?我有这样的抱负,也许有一天我会对Gradle少一点无知。它是CopySpec
接口的一部分(在您链接的应用程序插件文档的分发部分提到)。CopySpec
界面包含复制任务类型中使用的文件的大多数常见配置方法,如Copy
,Sync
,ProcessResources
,Jar
,War
,Tar
,Zip
,等等。