Writing a task of type Zip in custom plugin task


(sakshi) #1

I have a task to create a zip of the source code of the project in the Custom plugin:

class MakeSourceZipTask extends Zip{
def makeSourceZip(){
exclude ‘.gradle/’, ‘.idea/’, '
.iml’, 'dist/'
baseName = project.componentUtils.getComponentName()
version = project.componentUtils.getComponentVersion()
classifier = 'src’
destinationDir project.file("${project.tmpDistLoc}")



I figured out that the makeSourceZip() is never executed and the configurations are never set. If I am writing a task of type Copy, I make the task extend DefaultTask instead of type Copy by using a project.copy closure. But similar thing doesnt work here. Can anyone suggest something here.

(Dimitar Dimitrov) #2

Use Google, this topic has beaten to death on this forum, on StackOverflow and in the documentation of the Maven Publishing plugin.

(sakshi) #3

I have done that enough. Didn’t find anything useful. Could you share few links you think might help.

(Dimitar Dimitrov) #4

Sure, but you need you to do some work first to show that you are not trying to farm me to earn your salary - paste me a link to the Maven Publishing plugin page in the reference documentation.

(sakshi) #5


(Dimitar Dimitrov) #6

This is the DSL documentation for the Zip task. I asked for the:

Maven Publishing plugin page in the reference documentation

If you notice in the top-bar, the documentation is split in “DSL Reference”, “User Guide”, etc. By “reference documentation” I meant the “User Guide” section (apologies for using the incorrect term).

Now please try again.

(sakshi) #8

I am kind of lost here. I am here https://docs.gradle.org/current/userguide/userguide.html and I can see a full section ‘Extending the Build’, I have gone through these links again now but I dont find anything related to my query.

(Dimitar Dimitrov) #9

I gave you the name of the section:

(sakshi) #10

I am not getting it. Thanks anyways.

(Dimitar Dimitrov) #11

You see, the point is that with the current level of understanding you demonstrate, by giving you the code to copy paste I am not helping you. Next time you have a question (and you will have a question very soon) you’ll be back here, asking for somebody to do the work for you.

I wanted to hold your hand and teach you how to use the documentation, then ask you in return to teach me (and the Gradle Inc guys) what are your difficulties with the current documentation and what would have made it easier for you to use.

We spent 2 hours trying to find a link, which (at least for me) is the first hit on Google if I enter “gradle maven publishing plugin”. And in the end you come back with “I don’t get it. Thanks anyways [I’m going to ask somebody else]”

Any way, thank you fot the effort and to save further frustration for everybody, the code you need to copy paste is the snippet in section 34.2.2. Publishing custom artifacts

Next time please be more persistent :wink:

(sakshi) #12

Well, that’s not what I meant by my comment. I got to this link in the beginning when I read your first comment. However, this link or the section makes no sense to me. I don’t want to use the gradle maven publishing plugin neither do I want to publish custom artifacts. My problem is creating a task of type zip and posting a problem on this forum was the last thing that I did. Still I am nowhere close to my solution.

(Dimitar Dimitrov) #13

This is how you create a source jar (from the same place):

task sourceJar(type: Jar) {
    from sourceSets.main.allJava

You don’t need a custom task to do it.

(sakshi) #14

This is not what I asked. I know how to write a task to create a zip. I need to write it as a custom task for the same. Please ask for more clarification if the problem is unclear. But the solution you provided has no relation to my problem

(Dimitar Dimitrov) #15

I need to write it as a custom task for the same.

I challenge that - why do you need it as a custom task? I.e. what does it give you over applying the stock task?

It is more opaque and less maintainable.

BTW, the error in your task is that you are putting the configuration in your execution action, so it never gets executed because it is not configured.

(sakshi) #16

That is the requirement and cant be altered for now. I know the problem. If you can , pls suggest a solution

(Dimitar Dimitrov) #17

Use the standard zip task and move the configuration code to a plugin. That’s what I would do. But then if you have requirement…

(sakshi) #18

Thanks for the help.