user6796845
user6796845

Reputation:

Can I use local.properties to store some info?

Recently I use bintray-release to upload my library to maven.

As its readme said:

./gradlew clean build bintrayUpload -PbintrayUser=BINTRAY_USERNAME -PbintrayKey=BINTRAY_KEY -PdryRun=false

I think it's too boring to put many parameters every time I want to update my library version.So I store bintrayUser and bintrayKey into local.properties.

local properties:

ndk.dir=/home/coxier/Android/Sdk/ndk-bundle
sdk.dir=/home/coxier/Android/Sdk
bintrayUser=coxier
bintrayKey=xxxxx

However when I invoke:

 ./gradlew clean build bintrayUpload -PdryRun=false

I get an error:

  • What went wrong: Execution failed for task ':library:bintrayUpload'. Bintray user cannot be empty!

By the error log, I don't think my lib's build.gradle finds bintrayUser and bintrayKey.

Upvotes: 0

Views: 3738

Answers (2)

Venkata Rahul S
Venkata Rahul S

Reputation: 324

Did you look at the gradle.properties file?

Here is a simpler way using gradle.properties file:

Add your property say abc with a value v to the gradle.properties file like this

abc=v

In your build.gradle file, access this property as:

println project.properties['abc']

Here is the link: to Chapter 12 of the Gradle user guide

Upvotes: 1

user6796845
user6796845

Reputation:

After some tries,I found out solution.

Properties properties = new Properties()
InputStream inputStream = project.rootProject.file('local.properties').newDataInputStream() ;
properties.load( inputStream )
bintrayUser = properties.getProperty('bintrayUser')
bintrayKey = properties.getProperty('bintrayKey'

Upvotes: 0

Related Questions