Gradle
  1. Gradle
  2. GRADLE-1361

Fat jar cookbook example leads to error

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Resolution: Fixed
    • Affects Version/s: 0.9.2
    • Fix Version/s: 1.0-milestone-4

      Description

      I have a multiproject build and I put a fat jar task in one of the subprojects. I created the fat jar task similar to the one described in the cookbook - http://docs.codehaus.org/display/GRADLE/Cookbook#Cookbook-Creatingafatjar

      jar {
      from configurations.compile.collect

      { it.isDirectory() ? it : zipTree(it) }

      manifest

      { attributes 'Main-Class': 'com.benmccann.gradle.test.WebServer' }

      }

      Running it results in the following error:
      Cause: You can't change a configuration which is not in unresolved state!

      I'm not sure what this error means. It seems that this is a bug or the documentation should be updated.

        Activity

        Hide
        Ben McCann added a comment -

        I created a small example gradle project similar to mine which reproduces this error.

        Show
        Ben McCann added a comment - I created a small example gradle project similar to mine which reproduces this error.
        Hide
        Ben McCann added a comment - - edited

        It's much more complicated, but this seems to work:

        task deployJar(type: Jar, dependsOn: jar) {
          baseName = project.name + '-deploy'
          deps = configurations.runtime + configurations.archives.allArtifactFiles
          depClasses = { deps.collect { it.isDirectory() ? it : zipTree(it) } }
          from(depClasses) { 
            exclude 'META-INF/MANIFEST.MF'
          }
          manifest {
            attributes 'Main-Class': 'com.benmccann.test.frontend.server.WebServer'
          }
        }
        
        Show
        Ben McCann added a comment - - edited It's much more complicated, but this seems to work: task deployJar(type: Jar, dependsOn: jar) { baseName = project.name + '-deploy' deps = configurations.runtime + configurations.archives.allArtifactFiles depClasses = { deps.collect { it.isDirectory() ? it : zipTree(it) } } from(depClasses) { exclude 'META-INF/MANIFEST.MF' } manifest { attributes 'Main-Class': 'com.benmccann.test.frontend.server.WebServer' } }
        Hide
        Russ Egan added a comment -

        Hit this myself. Unfortunately, seems to run much much slower than the ant equivalent:

            <target name="fatJar" depends="jar">
                <jar destfile="${libs.dir}/${ant.project.name}-deploy-${version}.jar">
                    <zipgroupfileset dir="lib" includes="*.jar"/>
                    <fileset dir="${classes.main.dir}"/>
                </jar>
            </target>
        
        Show
        Russ Egan added a comment - Hit this myself. Unfortunately, seems to run much much slower than the ant equivalent: <target name= "fatJar" depends= "jar" > <jar destfile= "${libs.dir}/${ant.project.name}-deploy-${version}.jar" > <zipgroupfileset dir= "lib" includes= "*.jar" /> <fileset dir= "${classes.main.dir}" /> </jar> </target>
        Hide
        Szczepan Faber added a comment -

        I just fixed the cookbook example.

        //incorrect:
        from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
        
        //correct:
        from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
        

        Since we're passing closure to the from() method it means that the it will be evaluated at execution time. At execution time, the configuration is already resolved meaning that all dependencies are downloaded, etc.

        Show
        Szczepan Faber added a comment - I just fixed the cookbook example. //incorrect: from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } //correct: from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } Since we're passing closure to the from() method it means that the it will be evaluated at execution time. At execution time, the configuration is already resolved meaning that all dependencies are downloaded, etc.

          People

          • Assignee:
            Szczepan Faber
            Reporter:
            Ben McCann
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development