2016-05-02 4 views
0

私は答えが見つからないという単純な質問です。Gradle processリソースソースが壊れています。

特定の変数を置き換えて、私のSpringブートアプリケーションでbuild.gradleファイルにバージョンを設定したいとします。これは宣伝として動作します。

def tokens = [ 
    "version": 'project.version.toString()', 
    "projectName": project.name, 
    "groupId": rootProject.group, 
    "artifactId": project.name 
] 
processResources{ 
    filter (ReplaceTokens, tokens: tokens) 
    outputs.upToDateWhen{ false } 
} 

このコードは、しかし、また、それを破壊私も私のリソースに含めるのJavaキーストア、で何かを置き換えます。私がant matchersを使用して置き換えたいファイルでないものを除外すると、何もコピーされません。 '* .properties'を含める

リソースディレクトリ内のファイルの残りの部分をコピーしながら、特定のファイルに対してのみトークン置換を行う方法はありますか?非プロパティファイルに対して個別のコピータスクを定義する必要がありますか?

ありがとうございます!

+0

解決策が見つかりましたか? @ blur0224? –

+0

私はしていません。私は別の方向に行きました。 – blur0224

答えて

1

解決策は、processReousrcesタスクが実行されている間にバイナリファイルをスキップすることです。たとえば、私はexpand()を使って、テキストファイルのトークンをgradleスクリプトで計算された値に置き換えます。だから、

  1. は、ここで私は、ディレクトリsrc/main/resources/certs/下のファイルをスキップすることができます方法ですJKSはバイナリリソース

  • 移動し、それを提出スキップします。 doLast()は、jksファイルがリソースの終了時に適切な場所にコピーされることを保証します。

    ext { 
        commit = 'git rev-parse --short HEAD'.execute().text.trim() 
        branch = 'git rev-parse --abbrev-ref --symbolic HEAD'.execute().text.trim() 
    } 
    
    /** 
    * Processes the resources, excluding the certs while building. 
    */ 
    processResources { 
        // Exclude the certs files to be processed as text 
        exclude "**/certs/*" 
    
        expand(
        timestamp: new Date(), 
        commit: commit, 
        branch: branch, 
        version: project.version 
    ) 
    
        // Copy the jks file to the resources (classpath) 
        doLast { 
        copy { 
         from "src/main/resources/certs/server.jks" 
         into "$buildDir/classes/main/certs" 
        } 
        } 
    } 
    
  • 関連する問題