2012-05-11 3 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 
} 

Gradle은이 구문을 허용하지 않습니다. 나는이한다면 나는 작동 얻을 수 있습니다

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로 설정하십시오. 종속성에서 , 단순히 컴파일하거나 위의 나는 아파치 구성에 대한 기본 전이 = 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 
} 

에 속하는 임의의 다른 구성으로 구성을 포함한다.

는 테어의 의견에 따라 아래 편집 :

이 해결하는 것입니다?

//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을 사용하고 있으며, transitive false와 true를 사용할 때 종속성을 보여주는 것으로까지 괜찮습니다.

제가

있어서 상기 사용 true로 전이를 돌릴 때, I 75 종속성이 활성 프로젝트가 나는 경우 전이 false로 (64)를 갖는다. 와 유사한 검사를하고 빌드 유물을 확인 가치가

.

+0

이 Gradle을-1.0에서 작동하지 않습니다 – Tair

관련 문제