0

I am writing the below code to get the zip of my android project source code.

 project.task("myTask", type:Zip){
        baseName = "outputs"
        from (project.rootDir){
            include ('*')
            from ('gradle/wrapper/'){ include ('*') }
            exclude 'build/','.gradle/','.idea/','*.iml'
            from (project.projectDir)
            {
                include ('libs/')
                include ('*')
                exclude ('build/','*.iml')
                include ('src/**/*')
            }
            from ('gradle/')
            { include('*') }
        }
        destinationDir project.rootProject.buildDir
    }

This produces a source zip containing all the files. However, there is one correction that is required here. I want the subproject to include all the files in it inside my zip as in the directory structure should remain intact. But right now I get the empty project folder and its content outside that folder which changes its directory structure. Can anyone tel how to get that. Thanks in advace!!

sver
  • 866
  • 1
  • 19
  • 44
  • Why zip and not jar? The jar task with very little modification can already produce a `sources` jar that contains all your project source and resource files. see here: http://stackoverflow.com/questions/11474729/how-to-build-sources-jar-with-gradle – RaGe Feb 11 '16 at 00:52
  • I want a zip of the sourcecode. There is another link http://stackoverflow.com/questions/4822521/how-do-i-produce-a-zip-of-my-source-using-gradle?rq=1 . I tried this but the only difference Is I am using a custom plugin project and not directly using this my build.gradle. In my case, if I use the solution given in this link, it gives me error that it cannot recognize the property classifier. – sver Feb 11 '16 at 03:58
  • Possible duplicate of http://stackoverflow.com/questions/4822521/how-do-i-produce-a-zip-of-my-source-using-gradle – Balaji Katika Feb 11 '16 at 06:17
  • No, This is the same link I have shared above. I have tried this, doesn't work for me. Mostly because I am calling the custom plugin task from a different project. – sver Feb 11 '16 at 06:23
  • It should be `sourceSets` - note the *camelCase*. – Opal Feb 11 '16 at 10:07
  • ok, I'll try that. The project.ZipTree part is fine? – sver Feb 11 '16 at 10:13
  • I get an error : Could not find property 'sourceSets' on task ':network:makeSourceZipPlugin' – sver Feb 12 '16 at 05:11

1 Answers1

1

I found no help in case of custom plugin. There were few solutions I found but nothing worked in my case .Finally, this worked for me :

Task taskSourceZip = project.task("makeSourceZip", type:Zip){
        baseName = "source"
        from (project.rootDir){
            exclude ('*/*.iml')
            exclude 'sourceZip.zip'
        }
        destinationDir project.rootDir
    }
sver
  • 866
  • 1
  • 19
  • 44