0
屬性在我的劇本的gradle我已經能夠成功地讀取性能是這樣的:init.gradle讀取命令行
def environment = hasProperty('env') ? env : 'dev'
使用這個我可以執行構建腳本是這樣的:
gradlew clean assemble -Penv=prod
我試過把這個文件移動到init.gradle
的文件中。該文件被識別,我可以使用腳本中定義的其他屬性,但是我無法從命令行獲取任何內容。我怎樣才能做到這一點?
我init.gradle
文件:
allprojects {
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
project.ext['nexusDomainName'] = 'https://example.com/nexus'
project.ext['compileSdkVersion'] = 19
project.ext['buildToolsVersion'] = "19"
project.ext['minSdkVersion'] = 8
project.ext['targetSdkVersion'] = 19
project.ext['sourceCompatibility'] = '1.7'
project.ext['targetCompatibility'] = '1.7'
//hasProperty('release') is always false
project.ext['archiveType'] = hasProperty('release') ? '' : '-SNAPSHOT'
project.ext['archiveUrl'] = hasProperty('release') ? "$nexusDomainName/content/repositories/releases/" : "$nexusDomainName/content/repositories/snapshots/"
// This buildEnv property won't read either
project.ext['buildEnv'] = hasProperty('env') ? env : 'dev'
println "prepping for $buildEnv"
project.ext['archivesBaseNameSuffix'] = (project.ext['buildEnv'] == 'stage' || project.ext['buildEnv'] == 'dev') ? '-' + project.ext['buildEnv'] : ''
repositories {
mavenLocal()
maven {
credentials {
username 'username'
password 'password'
}
url "$nexusDomainName/content/groups/public/"
}
mavenCentral()
}
}
感謝您的快速回答! (抱歉我的延遲響應) – Sababado