# Cannot set readonly property: files

**URL:** <https://discuss.gradle.org/t/cannot-set-readonly-property-files/1967>\
**Category:** Old Forum Archive\
**Created:** [January 16, 2015, 1:48pm UTC](https://discuss.gradle.org/t/cannot-set-readonly-property-files/1967 "2015-01-16T13:48:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bioinfornatics](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/bioinfornatics/32/364_2.png) [@bioinfornatics](https://discuss.gradle.org/u/bioinfornatics)\
**Post date:** [January 16, 2015, 1:48pm UTC](https://discuss.gradle.org/t/cannot-set-readonly-property-files/1967/1 "2015-01-16T13:48:00Z")

</div>

Dear,

I fail to run this task:

```gradle
@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:

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

```

This task is created from the main class like this;

```gradle
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

---

<div class="post-metadata">

**Author:** ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)\
**Post date:** [January 16, 2015, 1:58pm UTC](https://discuss.gradle.org/t/cannot-set-readonly-property-files/1967/2 "2015-01-16T13:58:00Z")

</div>

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é

---

<div class="post-metadata">

**Author:** ![bioinfornatics](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/bioinfornatics/32/364_2.png) [@bioinfornatics](https://discuss.gradle.org/u/bioinfornatics)\
**Post date:** [January 16, 2015, 2:01pm UTC](https://discuss.gradle.org/t/cannot-set-readonly-property-files/1967/3 "2015-01-16T14:01:00Z")

</div>

Thanks you René,

This fix this Error but that throws a new one:

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

```

---

<div class="post-metadata">

**Author:** ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)\
**Post date:** [January 16, 2015, 2:21pm UTC](https://discuss.gradle.org/t/cannot-set-readonly-property-files/1967/4 "2015-01-16T14:21:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bioinfornatics](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/bioinfornatics/32/364_2.png) [@bioinfornatics](https://discuss.gradle.org/u/bioinfornatics)\
**Post date:** [January 16, 2015, 2:32pm UTC](https://discuss.gradle.org/t/cannot-set-readonly-property-files/1967/5 "2015-01-16T14:32:00Z")

</div>

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
