Gradle

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What’s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
To raise new issues or bugs against Gradle, please use forums.gradle.org.
  • Gradle
  • GRADLE-1361

Fat jar cookbook example leads to error

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Resolved 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.

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Hide
    Zip Archive
    example.zip
    02/Feb/11 10:56 AM
    13 kB
    Ben McCann
    1. File
      gradle/settings.gradle 0.1 kB
    2. File
      gradle/build.gradle 0.2 kB
    3. File
      gradle/.gradle/.../cache.properties 0.0 kB
    4. File
      gradle/.gradle/.../taskArtifacts/cache.bin 55 kB
    5. Java Source File
      gradle/java/com/.../frontend/Example.java 0.3 kB
    6. File
      gradle/java/com/.../frontend/build.gradle 0.3 kB
    7. Java Source File
      gradle/java/com/.../test/db/Db.java 0.2 kB
    8. File
      gradle/java/com/.../test/db/build.gradle 0.1 kB
    9. File
      gradle/java/.../cache.properties 0.0 kB
    10. File
      gradle/java/com/.../taskArtifacts/cache.bin 31 kB
    Download Zip
    Show
    Zip Archive
    example.zip
    02/Feb/11 10:56 AM
    13 kB
    Ben McCann

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • History
  • Activity
  • TeamCity
  • Commits
  • Source
  • Reviews
Hide
Permalink
Ben McCann added a comment - 02/Feb/11 10:56 AM

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

Show
Ben McCann added a comment - 02/Feb/11 10:56 AM I created a small example gradle project similar to mine which reproduces this error.
Hide
Permalink
Ben McCann added a comment - 03/Feb/11 3:01 AM - 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 - 03/Feb/11 3:01 AM - 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
Permalink
Russ Egan added a comment - 10/Jun/11 4:41 PM

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 - 10/Jun/11 4:41 PM 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
Permalink
Szczepan Faber added a comment - 21/Jun/11 7:15 AM

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 - 21/Jun/11 7:15 AM 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
Vote (0)
Watch (3)

Dates

  • Created:
    01/Feb/11 1:43 AM
    Updated:
    04/Jan/13 5:10 AM
    Resolved:
    21/Jun/11 7:15 AM
  • Atlassian JIRA (v5.0.3#729-sha1:bf569e4)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Gradle. Try JIRA - bug tracking software for your team.