gradle依赖关系未执行 [英] gradle dependency not being executed

查看:100
本文介绍了gradle依赖关系未执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的情况是这样:

  • 在打包此应用之前,我需要提取一个公共依赖项
  • 我将其一次拉到根目录,然后将其复制到子项目中以提高速度
  • 然后我需要构建
  • 将构建工件放入此复制的目录中

因此,当我运行此示例任务时,它将依赖项拉到根文件夹,但从不复制它,而我只是不明白为什么.以下是我整理的Kotlin版本

So, when I run this sample task, it pulls the dependency to the root folder but never copies it and I am just not seeing why. Below is my trimmed down kotlin build

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

我希望它会

  1. 拉动我在根项目中定义的依赖项
  2. 将其复制到本地项目
  3. 构建
  4. 在第2步中将生成dll复制到文件夹中

空转显示了我的期望:

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

但是执行实际上没有执行吗?!直接复制不会复制到本地项目中,而是复制到根项目中

but the execution doesn't actually do it?! The directly isn't copied in the the local project but it is in the root project

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>

最后,我看到基本上需要复制此代码(示例):

at the end I see to basically need to replicate this code (example):

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

推荐答案

关于复制任务的配置:

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)
    }
}

问题是您在执行复制任务期间对其进行了配置.因此,我认为您的任务没有配置,然后没有执行.

The issue is that you configuration your copy task during the its execution. So I think your tasks is not configured and then not executed.

您可以在中查看配置示例.Gradle Copy文档.没有 doLast 部分.

您的复制任务依赖于先前任务创建的文件/目录.我认为您应该考虑将文件放在此处,并使用include from来考虑一个模式,而不要考虑该文件确实在这里(这可以解释您为什么使用 doLast )

Your copy task are relying on file/directory that are created by an earlier task. I think you should considered that the file will be here and use include from regarding a pattern and not regarding that files are really here (which may explain why you used doLast)

示例:

val cpfms by register<Copy>("cpFms") {
    dependsOn(rootProject.tasks.named("pullfms"))
    from("**/PRISMDataAdaptor.dll")
    into("prism.core.fulfillmentmicroservice")
}

这篇关于gradle依赖关系未执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆