ZipTask Always Up-To-Date


The following task is always up-to-date and does not create a new zip file. What is wrong with it and what do I have to change

task createZip (type: Zip) { "archive"
    from temporaryDir
    baseName "database_${}"

	doFirst {
		FileCollection collect  = fileTree(dir:'database')
		File  versiondir = new File(temporaryDir, "sql" + File.separator + "system" + File.separator + datum);
		if (collect.isEmpty())	{
			logger.error 'No Files'

	    Set set = new HashSet()
	    boolean error = false
	    collect.each {File file ->
	        if(file.isFile() && file.getName().endsWith(".mac")) {
	            String absPath = file.getAbsolutePath()
	            String rootPath = file.getParentFile().getParentFile().getParent()
	            String pruefString  = absPath.substring(rootPath.length(), absPath.length())
	            if(! set.add(pruefString)) {
	            	logger.error 'duplicate SQL:\t' + file.getAbsolutePath()
	                error = true

	            if(!error) {
	            	copy {
	        			from file.getParentFile()
						into new File (temporaryDir, 'macs/' )
	    if(error) {
	        throw new GradleException('duplicate Files	')

	doLast {

Hi Dominik,

this task is always up to date since, when starting, it has no input files. The input files would only be copied during the doFirst block you added. I would suggest you convert the doFirst block to a separate task and then have createZip depend on it. Since you are copying files anyway the new task could be of type Copy. You could have a look if you can configure the copy spec of this copy task directly instead of doing it “by hand”.


Thanks for your quick reply. I’ve excludedit into a separate task. This has also worked. How can I use CopySpec? I have not found an example, but it would interest me.

cheers :slight_smile:

How about this:

task createZip(type: Zip) {
    baseName "database_${}"
    from {
    into 'macs'
    include '**/*.mac'
    includeEmptyDirs = false
    duplicatesStrategy = DuplicatesStrategy.FAIL

Does this do the same as your two tasks combined?

(And sorry about the late reply…)

1 Like