Programing

Gradle을 사용할 때 전이 종속성의 모든 인스턴스를 제외하려면 어떻게해야합니까?

lottogame 2020. 9. 15. 19:11
반응형

Gradle을 사용할 때 전이 종속성의 모든 인스턴스를 제외하려면 어떻게해야합니까?


내 gradle 프로젝트는 application플러그인을 사용하여 jar 파일을 빌드합니다. 런타임 전이 종속성의 일부로 org.slf4j:slf4j-log4j12. (적어도 5 개 또는 6 개의 다른 전이 종속성에서 하위 전이 종속성으로 참조됩니다.이 프로젝트는 spring과 hadoop을 사용하고 있으므로 부엌 싱크대를 제외한 모든 것이 끌어 들여지고 있습니다 ... 잠깐만 요 ... 그것도 있습니다 :) ).

내가 slf4j-log4j12만든 항아리에서 항아리 를 전역 적으로 제외하고 싶습니다 . 그래서 나는 이것을 시도했습니다.

configurations {
  runtime.exclude group: "org.slf4j", name: "slf4j-log4j12"
}

그러나, 이것은 제외 할 것 모두 org.slf4j 를 포함하여 유물을 slf4j-api. 디버그 모드에서 실행할 때 다음과 같은 줄이 표시됩니다.

org.slf4j#slf4j-api is excluded from com.pivotal.gfxd:gfxd-demo-mapreduce:1.0(runtime).
org.slf4j#slf4j-simple is excluded from com.pivotal.gfxd:gfxd-demo-mapreduce:1.0(runtime).
org.slf4j#slf4j-log4j12 is excluded from org.apache.hadoop:hadoop-common:2.2.0(runtime).

slf4j-log4j12전이 종속성 의 소스를 찾은 다음 compile foo { exclude slf4j... }dependencies블록에 개별 명령문 을 가질 필요가 없습니다 .

최신 정보:

나는 또한 이것을 시도했다 :

configurations {
  runtime.exclude name: "slf4j-log4j12"
}

결국 빌드에서 모든 것을 제외 합니다! 내가 지정한 것처럼 group: "*".

업데이트 2 :

이를 위해 Gradle 버전 1.10을 사용하고 있습니다.


아, 다음이 작동하고 내가 원하는 것을 수행합니다.

configurations {
  runtime.exclude group: "org.slf4j", module: "slf4j-log4j12"
}

이 보인다 규칙을 제외 만이 두 가지 특성 - groupmodule. 그러나 위의 구문은 임의의 속성을 조건 자로 지정하는 것을 방지하지 않습니다. 개별 종속성에서 제외하려고 할 때 임의의 속성을 지정할 수 없습니다. 예를 들어 다음은 실패합니다.

dependencies {
  compile ('org.springframework.data:spring-data-hadoop-core:2.0.0.M4-hadoop22') {
    exclude group: "org.slf4j", name: "slf4j-log4j12"
  }
}

No such property: name for class: org.gradle.api.internal.artifacts.DefaultExcludeRule

당신은과 종속성을 지정할 수 있습니다 그럼에도 불구 group:하고 name:당신은으로 제외를 지정할 수 없습니다 name:!?!

아마도 별도의 질문이지만 모듈정확히 무엇 입니까? groupId : artifactId : version의 Maven 개념을 이해할 수 있으며 Gradle에서 group : name : version으로 변환됩니다. 그러나 특정 Maven 아티팩트가 속한 모듈 (gradle-speak)을 어떻게 알 수 있습니까?


하나 이상의 라이브러리를 전역 적으로 제외하려면 build.gradle에 다음을 추가하십시오.

configurations.all {
   exclude group:"org.apache.geronimo.specs", module: "geronimo-servlet_2.5_spec"
   exclude group:"ch.qos.logback", module:"logback-core"
}

Now the exclude block has two properties group and module. For those of you coming from maven background, group is same as groupId and module is same as artifactId. Example: To exclude com.mchange:c3p0:0.9.2.1 following should be exclude block

exclude group:"com.mchange", module:"c3p0"

Your approach is correct. (Depending on the circumstances, you might want to use configurations.all { exclude ... }.) If these excludes really exclude more than a single dependency (I haven't ever noticed that when using them), please file a bug at http://forums.gradle.org, ideally with a reproducible example.


in the example bellow I exclude

spring-boot-starter-tomcat

compile("org.springframework.boot:spring-boot-starter-web") {
     //by both name and group
     exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat' 
}

I was using spring boot 1.5.10 and tries to exclude logback, the given solution above did not work well, I use configurations instead

configurations.all {
    exclude group: "org.springframework.boot", module:"spring-boot-starter-logging"
}

In addition to what @berguiga-mohamed-amine stated, I just found that a wildcard requires leaving the module argument the empty string:

compile ("com.github.jsonld-java:jsonld-java:$jsonldJavaVersion") {
    exclude group: 'org.apache.httpcomponents', module: ''
    exclude group: 'org.slf4j', module: ''
}

참고URL : https://stackoverflow.com/questions/21764128/how-do-i-exclude-all-instances-of-a-transitive-dependency-when-using-gradle

반응형