Gradle-Abhängigkeit wird nicht ausgeführt

Aug 25 2020

Meine Situation ist folgende:

  • Bevor ich diese App packen kann, muss ich eine gemeinsame Abhängigkeit ziehen
  • Ich ziehe es einmal in das Stammverzeichnis und kopiere es dann aus Geschwindigkeitsgründen in das Teilprojekt
  • Ich muss dann bauen
  • Legen Sie ein Build-Artefakt in diesem kopierten Verzeichnis ab

Wenn ich diese Beispielaufgabe ausführe, wird die Abhängigkeit in den Stammordner gezogen, aber nie kopiert, und ich verstehe nur nicht, warum. Unten ist mein abgespeckter 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"
    }
}

also wenn ich renne gradle :adaptor-cwi_ky_statewide_smd:cpFmsdll

Ich gehe davon aus, dass es so sein wird

  1. Ziehen Sie meine Abhängigkeit wie im Root-Projekt definiert
  2. Kopieren Sie es in das lokale Projekt
  3. bauen
  4. Kopieren Sie die Build-DLL in Schritt 2 in den Ordner

Der Trockenlauf zeigt, was ich erwarten würde:

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

aber die Hinrichtung macht es eigentlich nicht?! Das wird nicht direkt in das lokale Projekt kopiert, sondern in das Root-Projekt

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>

Am Ende sehe ich, dass dieser Code grundsätzlich repliziert werden muss (Beispiel):

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

Antworten

1 dwursteisen Sep 07 2020 at 10:02

In Bezug auf die Konfiguration Ihrer Kopieraufgabe:

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

Das Problem ist, dass Sie Ihre Kopieraufgabe während der Ausführung konfigurieren. Ich denke also, Ihre Aufgaben sind nicht konfiguriert und werden dann nicht ausgeführt.

Ein Beispiel für die Konfiguration finden Sie in der Dokumentation zu Gradle Copy . Es gibt keinen doLastTeil.

Ihre Kopieraufgabe basiert auf Dateien / Verzeichnissen, die von einer früheren Aufgabe erstellt wurden. Ich denke, Sie sollten bedenken, dass die Datei hier sein wird und Include in Bezug auf ein Muster verwendet und nicht in Bezug darauf, dass Dateien wirklich hier sind (was möglicherweise erklärt, warum Sie sie verwendet haben doLast).

Beispiel:

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

Ok, danke an @dwursteisen, dass du mich auf den richtigen Weg gebracht hast. Um dieses spezielle Problem zu lösen, musste die Delegierung verwendet werden:

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

Das funktioniert jetzt tatsächlich. Das obige Beispiel kann jedoch tatsächlich besser sein, da es einfach weniger kompliziert ist.