2017-05-09 11 views
1

グレードv3.4を使用しています。私はlocal.propertiesと呼ばれるファイル(build.gradleと同じディレクトリ)に次のプロパティを移動しました:設定プロパティbuild.gradle内のlocal.propertiesから読み取る

local.properties

nexusUsername=someuser 
nexusPassword=somepassword 

build.gradle

File secretPropsFile = file('./local.properties') 
if (secretPropsFile.exists()) { 
    Properties p = new Properties() 
    p.load(new FileInputStream(secretPropsFile)) 
    p.each { name, value -> 
     project.set name, value 
    } 
} else { 
    throw new IllegalStateException("secret.properties could not be located for build process") 
} 

を次の例外が発生します。

Could not find method set() for arguments [nexusUsername, someuser] on root project 'some-java-project of type org.gradle.api.Project. 

答えて

1

エラーは正しいです。プロパティを設定するには、extを使用する必要があります。​​をご覧ください。

File secretPropsFile = file('./local.properties') 
if (secretPropsFile.exists()) { 
    Properties p = new Properties() 
    p.load(new FileInputStream(secretPropsFile)) 
    p.each { name, value -> 
     ext[name] = value 
    } 
} else { 
    throw new IllegalStateException("secret.properties could not be located for build process") 
} 

println project.nexusPassword 
println project.nexusUsername //property is set in project's scope via ext 

だから、次のコードは、仕事をします

関連する問題