sver
sver

Reputation: 942

Groovy:The field properties is declared multiple times

I want to get the value of a variable in my custom plugin class from gradle.properties. But I want to write and use it outside the apply method. So, I am writing like this :

class VCPlugin implements Plugin<Project> {

   private Project project

   private Properties properties
   properties = new Properties()
   properties.load(project.rootProject.file('gradle.properties').newDataInputStream())
   def componentClass = properties.getProperty('componentClass')

   @Override
   void apply(Project project) {
      //applying distribution plugin
      this.project = project .....
   }
}

But this gives compile error:

Groovy:The field properties is declared multiple times

Now, if I write it inside the apply method, then it works but I need to use componentClass variable outside the apply method so I need to write this outside. Any help will be appreciated.

Upvotes: 0

Views: 948

Answers (1)

Opal
Opal

Reputation: 84804

Below code should do the job:

 class VCPlugin implements Plugin<Project> {

  private Project project
  private Properties properties
  private String componentClass 

  @Override
  void apply(Project project) {
    this.project = project
    this.properties = new Properties()
    properties.load (project.rootProject.file('gradle.properties').newDataInputStream())
    this.componentClass = this.properties.getProperty('componentClass')
  }
}

Upvotes: 1

Related Questions