Gradle plugin: Cant cast "A.txt" with class Java.io.File to class org.gradle.api.file.Property

Viewed 323

I am trying to write a plugin with DSL:

model {
 model1 {input = file(A.txt) output = file("/")}
 model2 {input = file(A.txt) output = file("/")}
}

and based on model1 and model2 I will do my processing and output the result in output directory.

​class Extension 
{
 final String name
 final Property<file> input
 final Property<file> output

 @Inject
 Extension(String name,ObjectFactory objectfactory)
 {
   this.name = name
   input = objectfactory.property(File)
   output = objectfactory.property(File)
 }

}

///Plugin class

class Plugin implements Plugin<Project> {
@Override
void apply(final Project project) {
    NamedDomainObjectContainer<Extension> container= project.container(Extension) {
            name -> new Extension(name, project.getObjects());
        }
    project.getExtensions().add("model", container);

    container.each {
            String taskName = "model" + name;
            project.tasks.create(taskName, Task)  {
                    input.set(input)
                    output.set(output)
                }
        }
}

} ​

//Task Class

class Deploy extends DefaultTask
{
  @InputFile
  Property<File> input = project.objects.property(File)


  @OutputFile
  Property<File> output= project.objects.property(File)

  @TaskAction
 def task()
 { 
   //custom logic
 }
}​

This code is highly inspired from https://guides.gradle.org/implementing-gradle-plugins/(ServerEnvironment Plugin)

But when I ran this I get Cant cast "A.txt" with class Java.io.File to class org.gradle.api.file.Property.

Can anybody tell what is the issue here and workaround.

Thanks

Extra Observation: WHen I change = with .set in my build.gradle error changs to stackoverflow

0 Answers
Related