2014-05-13 7 views
39

종속성 (전 이적 종속성이 아님) 내에있는 특정 파일을 다운로드하지 못하도록 할 것인지 궁금합니다.Gradle 종속성 내의 특정 파일 제외

저는 Ant + Ivy에서 Gradle로 빌드를 전환하고 있는데 이것은 이전에 Ivy에서 수행되었습니다. 내가 Artifactory에 컴파일 된 많은 wsdl jar를 포함하는 하나의 의존성을 가지고 있기 때문에 물어 본다.하지만 의존성에있는 모든 jar 파일을 다운로드하고 싶지는 않다.

아이비 그것은처럼 설정 :이 6 개 유물이 하나 개의 디렉토리의 repo/dep.location/예/7.3/항아리에 Artifactory에 게시 된

.

<publications> 
    <artifact name="foo-1-0" type="jar" /> 
    <artifact name="foo-1-0-async" type="jar" /> 
    <artifact name="foo-1-0-xml" type="jar" /> 
    <artifact name="bar-1-0" type="jar" /> 
    <artifact name="bar-1-0-async" type="jar" /> 
    <artifact name="bar-1-0-xml" type="jar" /> 
</publications> 

이렇게하면 6 개의 아티팩트 중 2 개만 검색하는 방법입니다.

<dependency org="dep.location" name="example" rev="7.3" 
      conf="compile,runtime"> 
    <include name="foo-1-0-async"/> 
    <include name="foo-1-0-xml"/> 
</dependency> 

현재 내가 Gradle에서 비슷한 작업을 시도하면 제외가 무시되고 여섯 개의 아티팩트가 모두 다운로드됩니다.

compile (group:"dep.location", name:"example", version:"7.3") 
{ 
    exclude module:'foo-1-0-xml' 
    exclude module:'bar-1-0' 
    exclude module:'bar-1-0-async' 
    exclude module:'bar-1-0-xml' 
} 

나는 1.8 버전의 Gradle을 사용하고 있습니다.

+0

제외하려는 것은 모듈이 아니라 아티팩트입니다. 내가 알고있는 Gradle의 유물을 포함/제외하는 유일한 지원 방법은 유형별로 지원되는데, 여기서는 도움이되지 않습니다. –

+0

이것은 gradle에서는 지원되지 않습니다. 그러나 대안은 당신이 예술 작품에 게시하는 방법을 바꾸는 것입니다. artifactory에서 개별 jar 파일을 게시하는 이유는 무엇입니까? – vkg

+0

좋아, 고마워. – bhumphrey

답변

3

Gradle에는이 작업을 지원하는 기능이 내장되어 있다고 생각하지 않지만 클래스 경로에서 직접 아티팩트를 정리할 수 있습니다. Gradle을 포럼에 this thread에서 영감을

나는이 함께했다 : Gradle을 아마 여전히 파일을 다운로드하고 당신을 위해 그들을 캐시,하지만 그들은 당신의 클래스 경로에 있으면 안됩니다

// The artifacts we don't want, dependency as key and artifacts as values 
def unwantedArtifacts = [ 
    "dep.location:example": [ "foo-1-0-xml", "bar-1-0", "bar-1-0-async", "bar-1-0-xml"], 
] 

// Collect the files that should be excluded from the classpath 
def excludedFiles = configurations.compile.resolvedConfiguration.resolvedArtifacts.findAll { 
    def moduleId = it.moduleVersion.id 
    def moduleString = "${moduleId.group}:${moduleId.name}:${moduleId.version}" // Construct the dependecy string 
    // Get the artifacts (if any) we should remove from this dependency and check if this artifact is in there 
    it.name in (unwantedArtifacts.find { key, value -> moduleString.startsWith key }?.value) 
}*.file 

// Remove the files from the classpath 
sourceSets { 
    main { 
     compileClasspath -= files(excludedFiles) 
    } 
    test { 
     compileClasspath -= files(excludedFiles) 
    } 
} 

하는 것으로.

+0

Gradle은 지원 기능을 내장하고 있습니다. 그것은 '해결 전략'입니다 – smilyface

+0

해상도 전략을 사용하여 어떤 인공물을 해결할 것인지 확신 할 수 없습니다. – Raniz

1

우리가 Spring Boot와 Wildfly를 사용하고 있기 때문에 이것이 확실한지는 모르겠지만 Spring Boot 표준 패키지에서 Tomcat-Starter 모듈을 제거해야합니다. 했어. 그러나, 우리의 코드는 상태 : 해당 항아리 다운로드하거나 그냥 클래스 경로에 있지 않은 경우 내가 확인하지 않은

configurations { 
    compile.exclude module: "spring-boot-starter-tomcat" 
} 

, 나는 그것을 더 이상 사용되지 않음을하지만 알고 있습니다.