2012-05-11 14 views
2

Gradleを使用して、依存関係のあるグループで推移性を無効にできるようにしたいと考えています。このようなもの:Gradleで依存関係のグループのプロパティを指定する方法は?

// transitivity enabled 
compile(
    [group: 'log4j', name: 'log4j', version: '1.2.16'], 
    [group: 'commons-beanutils', name: 'commons-beanutils', version: '1.7.0'] 
) 

// transitivity disabled 
compile(
    [group: 'commons-collections', name: 'commons-collections', version: '3.2.1'], 
    [group: 'commons-lang', name: 'commons-lang', version: '2.6'], 
) { 
    transitive = false 
} 

この構文は受け入れません。 I 私はこれを行う場合、それが動作するように取得することができます:

compile(group: 'commons-collections', name: 'commons-collections', version: '3.2.1') { transitive = false } 
compile(group: 'commons-lang', name: 'commons-lang', version: '2.6']) { transitive = false } 

しかし、それはときに私はむしろ、グループ一緒にしたい、各依存関係のプロパティを指定するために私を必要とします。

誰でもこのことに役立つ構文の提案がありますか?

答えて

5

まず、宣言を簡略化(または少なくとも短縮)する方法があります。

compile 'commons-collections:commons-collections:[email protected]' 
compile 'commons-lang:commons-lang:[email protected]' 

または::たとえば

def nonTransitive = { transitive = false } 

compile 'commons-collections:commons-collections:3.2.1', nonTransitive 
compile 'commons-lang:commons-lang:2.6', nonTransitive 

作成、構成、および一度に複数の依存関係を追加するために、あなたは少し抽象化を導入する必要があります。次のようなものがあります。

def deps(String... notations, Closure config) { 
    def deps = notations.collect { project.dependencies.create(it) } 
    project.configure(deps, config) 
} 

dependencies { 
    compile deps('commons-collections:commons-collections:3.2.1', 
      'commons-lang:commons-lang:2.6') { 
     transitive = false 
    } 
} 
3

個別の設定を作成し、目的の設定で推移= falseを設定します。依存関係で は、単にコンパイルまたは彼らは上記の私は、Apacheの設定のデフォルトの推移= trueを適用している間、私は、ログ関連のリソースの推移の依存関係を無効にすることができます

configurations { 
    apache 
    log { 
     transitive = false 
     visible = false //mark them private configuration if you need to 
    } 
} 

dependencies { 
    apache 'commons-collections:commons-collections:3.2.1' 
    log 'log4j:log4j:1.2.16' 

    compile configurations.apache 
    compile configurations.log 
} 

に属し、他の構成に構成を含みます。 TAIRさんのコメントにつき、以下のように編集された

これは修正でしょうか?

//just to show all configurations and setting transtivity to false 
configurations.all.each { config-> 
    config.transitive = true 
    println config.name + ' ' + config.transitive 
} 

と依存関係を表示するために Gradleの依存関係

を実行します。私はGradle-1.0を使用しています。これは、推移的な偽と真の両方を使用する場合、依存関係を示す限りOKです。

私は、上記の方法を使用して推移すると、75の依存関係があり、推移がfalseのときに64があるアクティブなプロジェクトがあります。

同様のチェックを行いビルド成果物をチェックする価値があります。

+0

これはgradle-1.0では機能しません – Tair

関連する問題