Gradle build - Resolve dependencies from downloaded archive











up vote
0
down vote

favorite












I'm fairly new to Gradle. I have a multi-project build that uses some dependencies currently packaged within the project (using repositories and flatDir), as they're not available in an artifactory.
I want to remove this local folder and download a couple of archives holding these dependencies, unpack them and proceed with the build as regular. I will use https://plugins.gradle.org/plugin/de.undercouch.download for downloading, but I don't know how to this before any dependency resolution (and ideally, download if not already done). Currently, the build fails in the configuration phase as far as I can tell:



  `A problem occurred configuring project ':sub-project-A'.
> Could not resolve all files for configuration ':sub-project-A:compileCopy'.
Could not find :<some-dependency>:.


EDIT: Downloading the files works. Still struggling with unzipping the archives:



task unzipBirt(dependsOn: downloadPackages, type: Copy) {
println 'Unpacking archiveA.zip'
from zipTree("${projectDir}/lib/archiveA.zip")
include "ReportEngine/lib"
into "${projectDir}/new_libs"
}


How do I make this run in the configuration phase ?










share|improve this question




























    up vote
    0
    down vote

    favorite












    I'm fairly new to Gradle. I have a multi-project build that uses some dependencies currently packaged within the project (using repositories and flatDir), as they're not available in an artifactory.
    I want to remove this local folder and download a couple of archives holding these dependencies, unpack them and proceed with the build as regular. I will use https://plugins.gradle.org/plugin/de.undercouch.download for downloading, but I don't know how to this before any dependency resolution (and ideally, download if not already done). Currently, the build fails in the configuration phase as far as I can tell:



      `A problem occurred configuring project ':sub-project-A'.
    > Could not resolve all files for configuration ':sub-project-A:compileCopy'.
    Could not find :<some-dependency>:.


    EDIT: Downloading the files works. Still struggling with unzipping the archives:



    task unzipBirt(dependsOn: downloadPackages, type: Copy) {
    println 'Unpacking archiveA.zip'
    from zipTree("${projectDir}/lib/archiveA.zip")
    include "ReportEngine/lib"
    into "${projectDir}/new_libs"
    }


    How do I make this run in the configuration phase ?










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm fairly new to Gradle. I have a multi-project build that uses some dependencies currently packaged within the project (using repositories and flatDir), as they're not available in an artifactory.
      I want to remove this local folder and download a couple of archives holding these dependencies, unpack them and proceed with the build as regular. I will use https://plugins.gradle.org/plugin/de.undercouch.download for downloading, but I don't know how to this before any dependency resolution (and ideally, download if not already done). Currently, the build fails in the configuration phase as far as I can tell:



        `A problem occurred configuring project ':sub-project-A'.
      > Could not resolve all files for configuration ':sub-project-A:compileCopy'.
      Could not find :<some-dependency>:.


      EDIT: Downloading the files works. Still struggling with unzipping the archives:



      task unzipBirt(dependsOn: downloadPackages, type: Copy) {
      println 'Unpacking archiveA.zip'
      from zipTree("${projectDir}/lib/archiveA.zip")
      include "ReportEngine/lib"
      into "${projectDir}/new_libs"
      }


      How do I make this run in the configuration phase ?










      share|improve this question















      I'm fairly new to Gradle. I have a multi-project build that uses some dependencies currently packaged within the project (using repositories and flatDir), as they're not available in an artifactory.
      I want to remove this local folder and download a couple of archives holding these dependencies, unpack them and proceed with the build as regular. I will use https://plugins.gradle.org/plugin/de.undercouch.download for downloading, but I don't know how to this before any dependency resolution (and ideally, download if not already done). Currently, the build fails in the configuration phase as far as I can tell:



        `A problem occurred configuring project ':sub-project-A'.
      > Could not resolve all files for configuration ':sub-project-A:compileCopy'.
      Could not find :<some-dependency>:.


      EDIT: Downloading the files works. Still struggling with unzipping the archives:



      task unzipBirt(dependsOn: downloadPackages, type: Copy) {
      println 'Unpacking archiveA.zip'
      from zipTree("${projectDir}/lib/archiveA.zip")
      include "ReportEngine/lib"
      into "${projectDir}/new_libs"
      }


      How do I make this run in the configuration phase ?







      gradle download task multi-project external-dependencies






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 6 at 15:09

























      asked Nov 5 at 18:05









      joanna

      3732925




      3732925
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          See Project.files(Object...) which states




          You can pass any of the following types to this method:



          ...



          A Task. Converted to the task's output files. The task is executed if the file collection is used as an input to another task.




          So you can do:



          task download(type: Download) {
          ...
          into "$buildDir/download" // I'm guessing the config here
          }
          task unzip {
          dependsOn download
          inputs.dir "$buildDir/download"
          outputs.dir "$buildDir/unzip"
          doLast {
          // use project.copy here instead of Copy task to delay the zipTree(...)
          copy {
          from zipTree("$buildDir/download/archive.zip")
          into "$buildDir/unzip"
          }
          }
          }
          task dependency1 {
          dependsOn unzip
          outputs.file "$buildDir/unzip/dependency1.jar"
          }
          task dependency2 {
          dependsOn unzip
          outputs.file "$buildDir/unzip/dependency2.jar"
          }
          dependencies {
          compile files(dependency1)
          testCompile files(dependency2)
          }


          Note: if there's lots of jars in the zip you can do



          ['dependency1', 'dependency2', ..., 'dependencyN'].each {
          tasks.create(it) {
          dependsOn unzip
          outputs.file "$buildDir/unzip/${it}.jar"
          }
          }





          share|improve this answer























          • Managed to get the download working. Can't extract the files though, I think it's a build life cycle issue I don't full understand yet
            – joanna
            Nov 6 at 13:36










          • Perhaps you are forcing the Configuration to resolve() in the configuration phase instead of the execution phase. If this is the case then the tasks don't have a chance to execute. See Build Phases
            – lance-java
            Nov 7 at 8:25










          • I'm sure I do, I just don't really understand the trigger. In the sub project I have some local dependencies defined for a configuration like this:[name: '<some_dependency>']. Defining them this way forces the resolution in the configuration phase ?
            – joanna
            Nov 7 at 10:34












          • Whoops, I think it was my original solution which had build lifecycle issues. Please see my updated solution
            – lance-java
            Nov 7 at 11:41


















          up vote
          0
          down vote













          I ended up using copy to force the unzip in the configuration phase



          copy {
          ..
          from zipTree(zipFile)
          into outputDir
          ..
          }





          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53159834%2fgradle-build-resolve-dependencies-from-downloaded-archive%23new-answer', 'question_page');
            }
            );

            Post as a guest
































            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            See Project.files(Object...) which states




            You can pass any of the following types to this method:



            ...



            A Task. Converted to the task's output files. The task is executed if the file collection is used as an input to another task.




            So you can do:



            task download(type: Download) {
            ...
            into "$buildDir/download" // I'm guessing the config here
            }
            task unzip {
            dependsOn download
            inputs.dir "$buildDir/download"
            outputs.dir "$buildDir/unzip"
            doLast {
            // use project.copy here instead of Copy task to delay the zipTree(...)
            copy {
            from zipTree("$buildDir/download/archive.zip")
            into "$buildDir/unzip"
            }
            }
            }
            task dependency1 {
            dependsOn unzip
            outputs.file "$buildDir/unzip/dependency1.jar"
            }
            task dependency2 {
            dependsOn unzip
            outputs.file "$buildDir/unzip/dependency2.jar"
            }
            dependencies {
            compile files(dependency1)
            testCompile files(dependency2)
            }


            Note: if there's lots of jars in the zip you can do



            ['dependency1', 'dependency2', ..., 'dependencyN'].each {
            tasks.create(it) {
            dependsOn unzip
            outputs.file "$buildDir/unzip/${it}.jar"
            }
            }





            share|improve this answer























            • Managed to get the download working. Can't extract the files though, I think it's a build life cycle issue I don't full understand yet
              – joanna
              Nov 6 at 13:36










            • Perhaps you are forcing the Configuration to resolve() in the configuration phase instead of the execution phase. If this is the case then the tasks don't have a chance to execute. See Build Phases
              – lance-java
              Nov 7 at 8:25










            • I'm sure I do, I just don't really understand the trigger. In the sub project I have some local dependencies defined for a configuration like this:[name: '<some_dependency>']. Defining them this way forces the resolution in the configuration phase ?
              – joanna
              Nov 7 at 10:34












            • Whoops, I think it was my original solution which had build lifecycle issues. Please see my updated solution
              – lance-java
              Nov 7 at 11:41















            up vote
            0
            down vote













            See Project.files(Object...) which states




            You can pass any of the following types to this method:



            ...



            A Task. Converted to the task's output files. The task is executed if the file collection is used as an input to another task.




            So you can do:



            task download(type: Download) {
            ...
            into "$buildDir/download" // I'm guessing the config here
            }
            task unzip {
            dependsOn download
            inputs.dir "$buildDir/download"
            outputs.dir "$buildDir/unzip"
            doLast {
            // use project.copy here instead of Copy task to delay the zipTree(...)
            copy {
            from zipTree("$buildDir/download/archive.zip")
            into "$buildDir/unzip"
            }
            }
            }
            task dependency1 {
            dependsOn unzip
            outputs.file "$buildDir/unzip/dependency1.jar"
            }
            task dependency2 {
            dependsOn unzip
            outputs.file "$buildDir/unzip/dependency2.jar"
            }
            dependencies {
            compile files(dependency1)
            testCompile files(dependency2)
            }


            Note: if there's lots of jars in the zip you can do



            ['dependency1', 'dependency2', ..., 'dependencyN'].each {
            tasks.create(it) {
            dependsOn unzip
            outputs.file "$buildDir/unzip/${it}.jar"
            }
            }





            share|improve this answer























            • Managed to get the download working. Can't extract the files though, I think it's a build life cycle issue I don't full understand yet
              – joanna
              Nov 6 at 13:36










            • Perhaps you are forcing the Configuration to resolve() in the configuration phase instead of the execution phase. If this is the case then the tasks don't have a chance to execute. See Build Phases
              – lance-java
              Nov 7 at 8:25










            • I'm sure I do, I just don't really understand the trigger. In the sub project I have some local dependencies defined for a configuration like this:[name: '<some_dependency>']. Defining them this way forces the resolution in the configuration phase ?
              – joanna
              Nov 7 at 10:34












            • Whoops, I think it was my original solution which had build lifecycle issues. Please see my updated solution
              – lance-java
              Nov 7 at 11:41













            up vote
            0
            down vote










            up vote
            0
            down vote









            See Project.files(Object...) which states




            You can pass any of the following types to this method:



            ...



            A Task. Converted to the task's output files. The task is executed if the file collection is used as an input to another task.




            So you can do:



            task download(type: Download) {
            ...
            into "$buildDir/download" // I'm guessing the config here
            }
            task unzip {
            dependsOn download
            inputs.dir "$buildDir/download"
            outputs.dir "$buildDir/unzip"
            doLast {
            // use project.copy here instead of Copy task to delay the zipTree(...)
            copy {
            from zipTree("$buildDir/download/archive.zip")
            into "$buildDir/unzip"
            }
            }
            }
            task dependency1 {
            dependsOn unzip
            outputs.file "$buildDir/unzip/dependency1.jar"
            }
            task dependency2 {
            dependsOn unzip
            outputs.file "$buildDir/unzip/dependency2.jar"
            }
            dependencies {
            compile files(dependency1)
            testCompile files(dependency2)
            }


            Note: if there's lots of jars in the zip you can do



            ['dependency1', 'dependency2', ..., 'dependencyN'].each {
            tasks.create(it) {
            dependsOn unzip
            outputs.file "$buildDir/unzip/${it}.jar"
            }
            }





            share|improve this answer














            See Project.files(Object...) which states




            You can pass any of the following types to this method:



            ...



            A Task. Converted to the task's output files. The task is executed if the file collection is used as an input to another task.




            So you can do:



            task download(type: Download) {
            ...
            into "$buildDir/download" // I'm guessing the config here
            }
            task unzip {
            dependsOn download
            inputs.dir "$buildDir/download"
            outputs.dir "$buildDir/unzip"
            doLast {
            // use project.copy here instead of Copy task to delay the zipTree(...)
            copy {
            from zipTree("$buildDir/download/archive.zip")
            into "$buildDir/unzip"
            }
            }
            }
            task dependency1 {
            dependsOn unzip
            outputs.file "$buildDir/unzip/dependency1.jar"
            }
            task dependency2 {
            dependsOn unzip
            outputs.file "$buildDir/unzip/dependency2.jar"
            }
            dependencies {
            compile files(dependency1)
            testCompile files(dependency2)
            }


            Note: if there's lots of jars in the zip you can do



            ['dependency1', 'dependency2', ..., 'dependencyN'].each {
            tasks.create(it) {
            dependsOn unzip
            outputs.file "$buildDir/unzip/${it}.jar"
            }
            }






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 7 at 11:45

























            answered Nov 5 at 20:35









            lance-java

            15.8k12858




            15.8k12858












            • Managed to get the download working. Can't extract the files though, I think it's a build life cycle issue I don't full understand yet
              – joanna
              Nov 6 at 13:36










            • Perhaps you are forcing the Configuration to resolve() in the configuration phase instead of the execution phase. If this is the case then the tasks don't have a chance to execute. See Build Phases
              – lance-java
              Nov 7 at 8:25










            • I'm sure I do, I just don't really understand the trigger. In the sub project I have some local dependencies defined for a configuration like this:[name: '<some_dependency>']. Defining them this way forces the resolution in the configuration phase ?
              – joanna
              Nov 7 at 10:34












            • Whoops, I think it was my original solution which had build lifecycle issues. Please see my updated solution
              – lance-java
              Nov 7 at 11:41


















            • Managed to get the download working. Can't extract the files though, I think it's a build life cycle issue I don't full understand yet
              – joanna
              Nov 6 at 13:36










            • Perhaps you are forcing the Configuration to resolve() in the configuration phase instead of the execution phase. If this is the case then the tasks don't have a chance to execute. See Build Phases
              – lance-java
              Nov 7 at 8:25










            • I'm sure I do, I just don't really understand the trigger. In the sub project I have some local dependencies defined for a configuration like this:[name: '<some_dependency>']. Defining them this way forces the resolution in the configuration phase ?
              – joanna
              Nov 7 at 10:34












            • Whoops, I think it was my original solution which had build lifecycle issues. Please see my updated solution
              – lance-java
              Nov 7 at 11:41
















            Managed to get the download working. Can't extract the files though, I think it's a build life cycle issue I don't full understand yet
            – joanna
            Nov 6 at 13:36




            Managed to get the download working. Can't extract the files though, I think it's a build life cycle issue I don't full understand yet
            – joanna
            Nov 6 at 13:36












            Perhaps you are forcing the Configuration to resolve() in the configuration phase instead of the execution phase. If this is the case then the tasks don't have a chance to execute. See Build Phases
            – lance-java
            Nov 7 at 8:25




            Perhaps you are forcing the Configuration to resolve() in the configuration phase instead of the execution phase. If this is the case then the tasks don't have a chance to execute. See Build Phases
            – lance-java
            Nov 7 at 8:25












            I'm sure I do, I just don't really understand the trigger. In the sub project I have some local dependencies defined for a configuration like this:[name: '<some_dependency>']. Defining them this way forces the resolution in the configuration phase ?
            – joanna
            Nov 7 at 10:34






            I'm sure I do, I just don't really understand the trigger. In the sub project I have some local dependencies defined for a configuration like this:[name: '<some_dependency>']. Defining them this way forces the resolution in the configuration phase ?
            – joanna
            Nov 7 at 10:34














            Whoops, I think it was my original solution which had build lifecycle issues. Please see my updated solution
            – lance-java
            Nov 7 at 11:41




            Whoops, I think it was my original solution which had build lifecycle issues. Please see my updated solution
            – lance-java
            Nov 7 at 11:41












            up vote
            0
            down vote













            I ended up using copy to force the unzip in the configuration phase



            copy {
            ..
            from zipTree(zipFile)
            into outputDir
            ..
            }





            share|improve this answer

























              up vote
              0
              down vote













              I ended up using copy to force the unzip in the configuration phase



              copy {
              ..
              from zipTree(zipFile)
              into outputDir
              ..
              }





              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                I ended up using copy to force the unzip in the configuration phase



                copy {
                ..
                from zipTree(zipFile)
                into outputDir
                ..
                }





                share|improve this answer












                I ended up using copy to force the unzip in the configuration phase



                copy {
                ..
                from zipTree(zipFile)
                into outputDir
                ..
                }






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 8 at 8:51









                joanna

                3732925




                3732925






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53159834%2fgradle-build-resolve-dependencies-from-downloaded-archive%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest




















































































                    這個網誌中的熱門文章

                    Hercules Kyvelos

                    Tangent Lines Diagram Along Smooth Curve

                    Yusuf al-Mu'taman ibn Hud