Task has not declared any outputs despite executing actions

Hi, I’m an android developer and I have been trying to follow the doc to create an incremental task for my project. I have tried my best to follow the instructions as much as I can but still, it runs the task every time. Been struggled for whole night, what am I doing wrong? really need some help.

Task 'convertSettingsToXML' is not up-to-date because:
  Task has not declared any outputs despite executing actions.

My gradle version:
distributionUrl=https://services.gradle.org/distributions/gradle-6.6.1-bin.zip

build.gradle:

class SettingsToXMLConverter extends DefaultTask {
  @InputFiles
  public FileCollection sources

  @OutputDirectory
  public File outputDir

  @TaskAction
  void execute() {
    println "sourceFiles: $sources"
    println "outputDir: $outputDir"
    sources.each {
      inputFile ->
        def outputFile = project.file("$outputDir/dma_settings_gen.xml")
        //Perform some actions...
    }
  }
}
task convertSettingsToXML(type: SettingsToXMLConverter) {
  sources = fileTree(dir: System.getProperty('SharedDir'))
  outputDir = file("src/main/res/values")
}

The log:

Task ':app:convertSettingsToXML' is not up-to-date because:

Task has not declared any outputs despite executing actions.

sourceFiles: directory 'Phone/Shared'

outputDir: /Users/test/Developer/Phone/android/Service/src/main/res/values

In Groovy, specifying public on the class’s fields causes them to be fields (no getter/setter) rather than properties. The @InputFiles and @OutputDirectory annotations are ignored when they are on fields.

Delete public from sources and outputDir and you should see what you expected.

thanks, it finally works now!