Cannot set readonly property: files

Dear,

I fail to run this task:

@TaskAction
    def run(){
        configDir
         = "${project.projectDir}${File.separator}config"
        hibernateRevEngXml
= "${configDir}${File.separator}hibernate.reveng.xml"
        hibernateConfigXml
= "${configDir}${File.separator}hibernate.cfg.xml"
        hibernatePathDir
  = "${project.buildDir}${File.separator}generated"
        hibernateDir
      = new File( hibernatePathDir )
                  inputs.files
      = hibernateRevEngXml
        outputs.dir
       = hibernateDir
        doLast{
            configDir.exists()
  || configDir.mkdirs()
            hibernateDir.exists() || hibernateDir.mkdirs()
            checkDataBase( project )
            writeRevengConfigFile(project)
        }
    }

This raise an Exception:

> Cannot set readonly property: files for class: org.gradle.api.internal.tasks.DefaultTaskInputs

This task is created from the main class like this;

class HibernatePlugin implements Plugin<Project>{
      @Override
    void apply(Project project) {
        project.plugins.apply JavaPlugin
        project.extensions.create( 'database', Database)
        project.configurations { project }
        project.task("reveng", type: RevengTask )
    }
}

Thanks for your help

Regads

inputs.files is not a field and is not assignable. instead it is a method. so instead of

inputs.files = hibernateRevEngXml 
outputs.dir = hibernateDir 
try

inputs.files hibernateRevEngXml 
outputs.dir hibernateDir
cheers
René

Thanks you René,

This fix this Error but that throws a new one:

Cannot call TaskInputs.files(Object...) on task ':reveng' after task has started execution.

Indeed. there is more stuff wrong with your task. you mix up task configuration and task execution.

the task inputs and outputs must be declared during the configuration phase. change your task to

  class RevengeTask extends DefaultTask {



...



...



public RevengeTask() {





 configDir





  = "${project.projectDir}${File.separator}config"





 hibernateRevEngXml  = "${configDir}${File.separator}hibernate.reveng.xml"





 hibernateConfigXml  = "${configDir}${File.separator}hibernate.cfg.xml"





 hibernatePathDir

 = "${project.buildDir}${File.separator}generated"





 hibernateDir



  = new File( hibernatePathDir )





 inputs.files hibernateRevEngXml





 outputs.dir hibernateDir



}





  @TaskAction



def run(){





 configDir.exists()

 || configDir.mkdirs()





 hibernateDir.exists() || hibernateDir.mkdirs()





 checkDataBase( project )





 writeRevengConfigFile(project)



}  }  

another option (the even better one I think) is to put the configuration part into the plugin code. this means you would end up with something like this:

  class RevengeTask extends DefaultTask {

  ...

  ...

  @TaskAction



def run(){





 configDir.exists()

 || configDir.mkdirs()





 hibernateDir.exists() || hibernateDir.mkdirs()





 checkDataBase( project )





 writeRevengConfigFile(project)



}  }

 class HibernatePlugin implements Plugin{



@Override



void apply(Project project) {





 project.plugins.apply JavaPlugin





 project.extensions.create( 'database', Database)





 project.configurations { project }





 project.task("reveng", type: RevengTask ) {



configDir





  = "${project.projectDir}${File.separator}config"







hibernateRevEngXml  = "${configDir}${File.separator}hibernate.reveng.xml"







hibernateConfigXml  = "${configDir}${File.separator}hibernate.cfg.xml"







hibernatePathDir

 = "${project.buildDir}${File.separator}generated"







hibernateDir



  = new File( hibernatePathDir )







inputs.files hibernateRevEngXml







outputs.dir  hibernateDir

 }



}  }  

first of all don

Thanks you René I will do some test with this. I like the last syntax to externalize configuration phase. Where is the doc about it please?

Kinds regards