2016-09-20 4 views
0

mavenプラグインを使用するbuild.gradleファイルがあります。私はプロジェクトを構築し、アーティファクトをネクサスレポにアップロードしようとしています。ビルドとアップロードの部分はうまくいきましたが、私はバージョン名とコードを動的に設定しようとする問題にぶち当たっています。ここでの私のbuild.gradleファイル内の重要なタスクです:mavenDeployerが変数値を使用していません

uploadArchives { 
    repositories { 
     mavenDeployer { 
      snapshotRepository(url: "https://artifact.example.net/content/repositories/snapshots") { 
       authentication(userName: artifactUsername, password: artifactPassword) 
      } 

      pom.version = rootProject.ext.name.toString() + "-" + rootProject.ext.code.toString() + "-SNAPSHOT" 
      pom.artifactId = appId 
      pom.groupId = "com.example.mobile.android" 
     } 
    } 
} 

task getVersionCode(type: Exec) { 
    commandLine './getVersionCode.sh' 
    workingDir scriptDir 
    standardOutput = new ByteArrayOutputStream() 
    doLast { 
     rootProject.ext.code = standardOutput.toString() as Integer 
     println(code) 
    } 
} 

task getVersionName(type: Exec) { 
    commandLine './getVersionName.sh' 
    workingDir scriptDir 
    standardOutput = new ByteArrayOutputStream() 
    doLast { 
     rootProject.ext.name = standardOutput.toString() 
     println(rootProject.ext.name) 
    } 
} 

preBuild.dependsOn getVersionCode 
preBuild.dependsOn getVersionName 
uploadArchives.dependsOn getVersionCode 
uploadArchives.dependsOn getVersionName 

私は何を見つけることだが、getVersionCodeとgetVersionNameタスクはuploadArchivesタスクの実行前に実行していてもという変数rootProject.ext.nameとrootprojectです.ext.codeにはデフォルト値があり、タスクによって動的に設定される値はありません。私はその後、値それほどのように印刷することができ

rootProject.ext.name = "new Name" 

:私は、私のような変数に設定した場合ことを確認した

println(rootProject.ext.name) 

すべて動作することを、その後私はその同じ変数を使用しようとすると、私のmavenDeployerタスクから変数がデフォルト値にリセットされます。私はここで間違って何をしていますか?

答えて

0

'mustRunAfter'を追加してみてください。 preBuild.mustRunAfter getVersionCode

関連する問題