[GRADLE-159] Allow method org.gradle.api.tasks.bundling.AbstractArchiveTask.merge and mergeGroup to take files with jar extension) to be passed as argument Created: 16/Jul/08  Updated: 04/Jan/13  Resolved: 17/Jul/08

Status: Resolved
Project: Gradle
Affects Version/s: 0.2
Fix Version/s: None

Type: New Feature
Reporter: Dominick More Assignee: Hans Dockter
Resolution: Not A Bug Votes: 0


I'd like to do someting like this.

libs {
Project commonProject = project(':modules:jars:onepad_common')
Jar commonJar = commonProject.task(commonProject.name + '_jar')
task(this.project.name + '_jar').merge( commonJar.getArchivePath().getCanonicalPath())

{ exclude( 'META-INF/**') }


Comment by Hans Dockter [ 16/Jul/08 ]

I had not time to try this out yet and my brain might be missing something after a long day of work. But this should work already if project(':modules:jars:onepad_common') is execute before the current project. What happens if you execute the above?

BTW: In trunk we have now a reasonable naming schema for archive tasks

Comment by Dominick More [ 17/Jul/08 ]

The example in the user documentation myZipTask.merge('path1/otherArchive1.zip', 'path2/otherArchive.tar.gz') passes the arguments in a list context (which looks like a 2 argument method to a traditional programmer) but not as a list object even though the merge method takes a single list as an argument. This may be auto-magically handled by groovy (I don't know the nuances of it) but I was able to run the merge method correctly if I wrapped the single argument as a list:

task(this.project.name + '_jar').merge([ commonJar.getArchivePath().getCanonicalPath()])

{ exclude( 'META-INF/**') }


Maybe the documentation should explicitly document list arguments where they are appropriate to avoid confusion for us groovy-ignorant gradle builders.

Keep up the good work!!!

Comment by Hans Dockter [ 17/Jul/08 ]

The merge method takes a Java 5 varargs argument merge(Object... paths). We then do two things with the paths array. First we check if the last argument is a closure. If so we strip it off and apply it afterwards. Then we flatten the paths array (therefore your example above works).

In your case it would be easier to write:

{{task(this.project.name + '_jar').merge(commonJar.getArchivePath().getCanonicalPath()) { exclude( 'META-INF/**') }}

If this does not work, that would be a bug.

But you can also do: merge(someListWithPaths, aPath, anotherPath, anotherListWithPaths)

There has been a bug in the flatten behavior which occured under some circumstances. This is fixed in trunk.

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