我的情况是这样
因此,当我运行此示例任务时,它将依赖项拉到根文件夹,但从不复制它,而我只是不明白为什么。以下是我整理的Kotlin版本
import com.ullink.Msbuild
import java.io.File
plugins {
id("com.ullink.msbuild") version "3.8" apply false
}
subprojects {
apply(plugin = "com.ullink.msbuild")
val solution = projectDir.walkTopDown().find { it.extension == "sln" }!!
tasks {
val restore by register("restore", Exec::class) {
executable = "nuget"
args = listOf(
"restore", solution.canonicalPath,
"-Source",
(getenv("NUGET_SOURCE") ?: project.properties["package.sources"]) as String
)
}
val msbuild by named<Msbuild>("msbuild") {
dependsOn(restore)
solutionFile = solution
projectName = project.name
verbosity = "quiet"
targets = listOf("Clean", "Rebuild")
configuration = "Release"
}
val cpfms by register<Copy>("cpFms"){
dependsOn(rootProject.tasks.named("pullfms"))
doLast{
println("cpFms do last")
val from = projectDir
.listFiles()
.find{ it.isDirectory() && it.name.toLowerCase().startsWith("prism.core.fulfillmentmicroservice") }!!
println("making copy ${from} -> ${projectDir}")
from(from)
into(projectDir)
}
}
val build by named("build") {
dependsOn(msbuild)
}
val cpdll by register<Copy>("cpFmsdll") {
dependsOn(cpfms,build)
doLast{
println("cpFmsdll do last")
val from = projectDir.walkTopDown().find{ it.name == "PRISMDataAdaptor.dll" }!!
val to = projectDir.listFiles().find{ it.isDirectory() && it.name.toLowerCase().startsWith("prism.core.fulfillmentmicroservice") }!!
println("cp dll ${from} -> ${to}")
from(from)
into(to)
}
}
}
}
tasks{
val pullFms by register("pullfms", Exec::class) {
args = listOf(
"install", "PRISM.Core.FulfillmentMicroService",
"-Source", (getenv("NUGET_PUBLISH") ?: project.properties["publish.repo"]) as String
)
executable = "nuget"
}
}
所以当我跑步时
gradle :adaptor-cwi_ky_statewide_smd:cpFmsdll
我希望它会
空转显示了我的期望:
PS C:\Users\cbongiorno\dev\sterling\prism\prism-adaptors> gradle --dry-run :adaptor-cwi_ky_statewide_smd:cpFmsdll
:adaptor-cwi_ky_statewide_smd:assemble SKIPPED
:adaptor-cwi_ky_statewide_smd:check SKIPPED
:adaptor-cwi_ky_statewide_smd:restore SKIPPED
:adaptor-cwi_ky_statewide_smd:msbuild SKIPPED
:adaptor-cwi_ky_statewide_smd:build SKIPPED
:pullfms SKIPPED
:adaptor-cwi_ky_statewide_smd:cpFms SKIPPED
:adaptor-cwi_ky_statewide_smd:cpFmsdll SKIPPED
但是执行实际上并没有执行?!直接复制不会复制到本地项目中,而是复制到根项目中
PS C:\Users\cbongiorno\dev\sterling\prism\prism-adaptors> gradle :adaptor-cwi_ky_statewide_smd:cpFmsdll
> Task :adaptor-cwi_ky_statewide_smd:restore
MSBuild auto-detection: using msbuild version '15.5.180.51428' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\bin'.
All packages listed in packages.config are already installed.
> Task :pullfms
Feeds used:
https://repo.dev.backgroundcheck.com/nexus/repository/nuget-group/
Installing package 'PRISM.Core.FulfillmentMicroService' to 'C:\Users\cbongiorno\dev\sterling\prism\prism-adaptors'.
CACHE https://repo.dev.backgroundcheck.com/nexus/repository/nuget-group/FindPackagesById()?id='PRISM.Core.FulfillmentMicroService'&semVerLevel=2.0.0
Package "PRISM.Core.FulfillmentMicroService.0.0.77" is already installed.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.3/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 1m 6s
3 actionable tasks: 3 executed
PS C:\Users\cbongiorno\dev\sterling\prism\prism-adaptors> ls | select -Last 20
Directory: C:\Users\cbongiorno\dev\sterling\prism\prism-adaptors
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 7/14/2020 10:08 PM gradle
d----- 7/21/2020 3:36 PM infra
d----- 5/13/2020 4:17 AM PRISM-Adaptor-QC_LA_SaintBernard
d----- 8/25/2020 4:25 PM PRISM.Core.FulfillmentMicroService.0.0.77
d----- 7/14/2020 8:07 AM routeadaptor-apinationwide_msmj1_dre
d----- 5/13/2020 4:18 AM serviceadaptor-cwi_ky_statewide_smd
d----- 5/13/2020 4:18 AM serviceadaptor-cwi_ny_statewide
d----- 5/13/2020 4:18 AM serviceadaptor-qc_ny_statewide
-a---- 7/14/2020 8:07 AM 2581 .gitattributes
-a---- 8/25/2020 4:22 PM 13996 .gitignore
-a---- 8/25/2020 4:51 PM 6653 build.gradle.kts
-a---- 7/21/2020 3:36 PM 987 Dockerfile
-a---- 8/14/2020 4:28 PM 206 gradle.properties
-a---- 7/14/2020 10:08 PM 5764 gradlew
-a---- 7/14/2020 10:08 PM 2942 gradlew.bat
-a---- 7/21/2020 3:36 PM 2222 Jenkinsfile
-a---- 5/13/2020 4:17 AM 11565 PRISM-Adaptors.txt
-a---- 7/14/2020 8:07 AM 722 README.md
-a---- 8/25/2020 3:24 PM 416 settings.gradle.kts
-a---- 7/14/2020 8:07 AM 978 sh.exe.stackdump
PS C:\Users\cbongiorno\dev\sterling\prism\prism-adaptors> ls .\adaptor-cwi_ky_statewide_smd\
Directory: C:\Users\cbongiorno\dev\sterling\prism\prism-adaptors\adaptor-cwi_ky_statewide_smd
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 7/21/2020 1:24 PM build
d----- 7/21/2020 1:14 PM CWI_KY_STATEWIDE_SMDSol
-a---- 5/13/2020 4:17 AM 2581 .gitattributes
PS C:\Users\cbongiorno\dev\sterling\prism\prism-adaptors>
最后,我看到基本上需要复制此代码(示例):
nuget.exe restore CWI_TN_DAVIDSON_SMDSol\CWI_TN_DAVIDSON_SMDSol.sln -source "https://www.nuget.org/api/v2;http://prism-prod-oct/NuGetLocalServer/nuget"
MSBuild.exe C:\PRISMGit\adaptor-cwi_tn_davidson_smd\CWI_TN_DAVIDSON_SMDSol\CWI_TN_DAVIDSON_SMDSol.sln /t:Clean /p:Configuration=Release
MSBuild.exe C:\PRISMGit\adaptor-cwi_tn_davidson_smd\CWI_TN_DAVIDSON_SMDSol\CWI_TN_DAVIDSON_SMDSol.sln /t:Rebuild /p:Configuration=Release
Set-Location C:\PRISMGit\adaptor-cwi_tn_davidson_smd\CWI_TN_DAVIDSON_SMDSol\PRISM.Adaptor.CWI.TN.DAVIDSON.SMD\
$Package = Find-Package -Name PRISM.Core.FulfillmentMicroService -Source http://prism-prod-oct/NuGetLocalServer/nuget
NuGet.exe install $Package.Name -Version $Package.Version -source http://prism-prod-oct/NuGetLocalServer/nuget
Copy-Item -Path .\bin\Release\PRISMDataAdaptor.dll -Destination (".\"+$Package.Name+ "." + $Package.Version+"\") -Recurse -Force
答案 0 :(得分:1)
关于复制任务的配置:
val cpfms by register<Copy>("cpFms") {
dependsOn(rootProject.tasks.named("pullfms"))
doLast {
// ...
from(from)
into(projectDir)
}
}
val cpdll by register<Copy>("cpFmsdll") {
dependsOn(cpfms,build)
doLast {
// …
from(from)
into(to)
}
}
问题是您在执行复制任务期间对其进行了配置。因此,我认为您的任务没有配置,然后没有执行。
您可以在Gradle Copy documentation中看到一个配置示例。没有doLast
部分。
您的复制任务依赖于先前任务创建的文件/目录。
我认为您应该考虑该文件将在此处使用,并且使用include from作为一种模式,而不是该文件确实在此处(这可以解释您为什么使用doLast
的原因)
示例:
val cpfms by register<Copy>("cpFms") {
dependsOn(rootProject.tasks.named("pullfms"))
from("**/PRISMDataAdaptor.dll")
into("prism.core.fulfillmentmicroservice")
}
答案 1 :(得分:0)
好,感谢@dwursteisen将我带入正确的轨道。要解决此特定问题,需要使用委托:
val cpfms by register<Copy>("cpFms") {
dependsOn(rootProject.tasks.named("pullfms"))
val from by lazy {
rootProject.projectDir.listFiles()
.find { it.isDirectory() && it.name.toLowerCase().startsWith("prism.core.fulfillmentmicroservice") }
}
from(from)
into(projectDir)
}
现在,这确实有效。但是,上述示例实际上可能会更好,因为它只是简单一些而已。