Gradle clean erasing my file prior to ZIP task execution


I have the following simple task in my build:

task generateFile << { def file = new File("$buildDir/setclasspath.sh") file.text = "sample" outputs.file(file) } task createDistro(type: Zip, dependsOn: ['copyDependencies','packageEnvironments','jar', 'generateFile']) <<{ from generateClasspathScript { fileMode = 0755 into 'bin' } }

When I run gradle clean build I see the following output:

Cannot call TaskOutputs.file(Object) on task ':generateFile' after task has started execution. Check the configuration of task ':generateFile' as you may have misused '<<' at task declaration

How do I declare the task file creation outputs as an input to the zip task while also ensuring they happen in the execution phase?

If I leave off the << then the clean task wipes the generated file before the ZIP can use it. If I keep them, I get the above error.


It's the opposite as what is being suggested in the comments. You are trying to set the outputs in execution phase. The correct way to do what you are probably trying to do is for example:

task generateFile { def file = new File("$buildDir/setclasspath.sh") outputs.file(file) doLast { file.text = "sample" } }


  • How to draw text onto a jpg and resave it using system.drawing in c#
  • ListView does not show images after switching view mode
  • Animating Linear Gradient using CSS
  • How to write dependsOn in Custom plugin
  • springboot jta transaction rollback is not working
  • DSC Custom Resource Dependencies
  • Gradle minify all javascript
  • sbt multi-module project: dependence between projects
  • integrate POCO library in android ndk
  • CoreData basics – to-many relationship array data
  • Eloquent Relationship on Partial Match
  • XMLBeans Duplicate Class and Class Not Found Errors
  • “mvn clean generate-source” could not resolve dependencies
  • In Java, how can I construct a File from a resource?
  • Android Studio Can't Find tools.jar
  • Memory error in python- how to use more memory
  • xcode don't localize specific strings
  • CakePHP ACL tutorial initDB function warnings
  • How to revert to previous XCode version?
  • How can I speed up CURL tasks?
  • How to add git credentials to the build so it would be able to be used within a shell code?
  • How do I exclude a dependency in provided scope when running in Maven test scope?
  • Is there a way to do normal logging with EureakLog?
  • Time complexity of a program which involves multiple variables
  • Admob requires api-13 or later can I not deploy on old API-8 phones?
  • Test if a set exists before trying to drop it
  • Spark fat jar to run multiple versions on YARN
  • Asynchronous UI Testing in Xcode With Swift
  • Scrapy recursive link crawler
  • Spring Data JPA custom method causing PropertyReferenceException
  • NetLogo BehaviorSpace - Measure runs using reporters
  • Perl system calls when running as another user using sudo
  • SVN: Merging two branches together
  • Hibernate gives error error as “Access to DialectResolutionInfo cannot be null when 'hibernate.
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • How do I configure my settings file to work with unit tests?
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Binding checkboxes to object values in AngularJs