2016-04-28 9 views
0

カスタムプラグインクラスの変数の値をgradle.propertiesから取得したいとします。しかし、私はapplyメソッドの外でそれを書いて使いたいと思っています。だから、私はこのように書いている:Groovy:フィールドプロパティが複数回宣言されました

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 ..... 
    } 
} 

しかし、これはエラーをコンパイルできます:

Groovy:The field properties is declared multiple times

、私はapplyメソッド内でそれを書くならば、それは動作しますが、私は外componentClass変数を使用する必要があります私はこれを外部に書く必要があるので、適用メソッド。どんな助けもありがとう。コードの下

答えて

1

仕事をする必要があります。

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') 
    } 
} 
+0

はい、worked.Iは別の何かを考えていたこと。この簡単な解決策は私の頭を越えていませんでした。どのように助けてくれてありがとう。 – sver

関連する問題