[GRADLE-1480] org.gradle.api.tasks.bundling.Jar#getVersion() returns wrong value Created: 17/Apr/11  Updated: 04/Jan/13  Resolved: 19/Apr/11

Status: Resolved
Project: Gradle
Affects Version/s: 1.0-milestone-2
Fix Version/s: None

Type: Bug
Reporter: Marco Hunsicker Assignee: Peter Niederwieser
Resolution: Not A Bug Votes: 0

Attachments: Zip Archive gradle-issue.zip    

 Description   

While trying to create a fatjar out of certain project jars, I've been running into a minor problem:

If a subproject defines a version that is different from the default version specified within the main build.gradle, the project specific version is not accessible from the bundling task. Maybe it's just me misunderstanding or misusing the API.

Here's the basic code that creates the fat jar in the root project (the whole project data is attached):

allprojects

{ // define default version used by most subprojects version = '1.0' ... }

jar {
baseName = 'fatjar'
project.subprojects.each { subproject ->
subproject.tasks.withType(Jar).each

{ archiveTask -> from zipTree(archiveTask.archivePath) assert archiveTask.version == '1.0.6' }

}
}

"archiveTask.archivePath" yields the root project default version!

To reproduce, unzip the attached project, change into directory "gradle-issue" and execute

$ gradle jar

It shows here:

FAILURE: Build failed with an exception.

  • Where:
    Build file '/home/John Doo/Documents/gradle-issue/build.gradle' line: 49
  • What went wrong:
    A problem occurred evaluating root project 'gradle'.
    Cause: assert archiveTask.version == '1.0.6'
       
    1.0 false
    task ':bug:jar'

It's not a major problem for me, as there are workarounds, but I'd thought I better let you know.

If this is not a bug, I would appreciate any explanation you can provide. Thank you.



 Comments   
Comment by Marco Hunsicker [ 17/Apr/11 ]

Looks like I did not understand the way Gradle performs project evaluation. This issue can be CLOSED

Generated at Wed Jun 30 11:56:35 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.