2016-10-14 12 views
2

私の依存関係のいくつかは別のファイルにあるという要件があります。どうすればこれを達成できますか? docs.gradle.org上のサンプルのうちの1つは、次のとおりです。このような依存関係とリポジトリを別のファイルに置くことはできますか?

List groovy = ["org.codehaus.groovy:groovy-all:[email protected]", 
      "commons-cli:commons-cli:[email protected]", 
      "org.apache.ant:ant:[email protected]"] 
List hibernate = ['org.hibernate:hibernate:[email protected]', 
       'somegroup:someorg:[email protected]'] 

dependencies { 
    runtime groovy, hibernate 
} 

何かが働くだろうが、私も同じファイルに私のリポジトリを指定したいと思います。

編集:私はthoug、

dependencies

stuff.gradle

repositories { 
    maven { 
     credentials { 
      username 'stuff' 
      password 'stuff' 
     } 
     url 'stuff' 
    } 
} 

dependencies { 
    compile 'things' 
} 

そしてbuild.gradle

apply from: 'path/to/stuff.gradle'

を思い付いた

ソリューション私はそれが違いを生むかどうか分からない。それは驚くほど簡単でした。 apply文とは別にbuild.gradleに変更はありませんでしたが、それでも通常のrepositoriesdependenciesのクロージャがあります。私を正しい軌道に乗せるためのオパールのおかげです。ここで

答えて

2

あなたが行く:

lol.gradle:リポジトリがリストとして保持することができるので

ext.repos = { mavenCentral(); mavenLocal() } 

ext.groovy = [ 
      "org.codehaus.groovy:groovy-all:[email protected]", 
      "commons-cli:commons-cli:[email protected]", 
      "org.apache.ant:ant:[email protected]", 
      ] 
ext.hibernate = [ 
      'org.hibernate:hibernate:[email protected]', 
      ] 

build.gradle

apply from: 'lol.gradle' 
apply plugin: 'java' 

repositories repos 

dependencies { 
    runtime groovy, hibernate 
} 

、最も簡単な方法を回避策のないリポジトリを保持するには、クロージャを使用します。リポジトリを保持するためにリストを使用すると、mavenLocalmavenCentralの両方のメソッド解決エラーで失敗します。

あなたは、次のコードを使用することができますが、リストとしてリポジトリを維持することを好む場合:

lol.gradleを

ext.repos = ['mavenCentral', 'mavenLocal',] 

ext.groovy = [ 
      "org.codehaus.groovy:groovy-all:[email protected]", 
      "commons-cli:commons-cli:[email protected]", 
      "org.apache.ant:ant:[email protected]", 
      ] 
ext.hibernate = [ 
      'org.hibernate:hibernate:[email protected]', 
      ] 

build.gradle

apply from: 'lol.gradle' 
apply plugin: 'java' 

repositories { r -> 
    repos.each { n -> r."$n"() } 
} 

dependencies { 
    runtime groovy, hibernate 
} 
+0

私の要件を明確にする必要があるかもしれません。 build.gradleにいくつかの依存関係を残し、別のファイルから他のものを追加したいと思います。 – DariusL

関連する問題