source

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

lovecheck 2022. 11. 28. 21:16
반응형

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

그래들 프로젝트에서는applicationjar 파일을 빌드하기 위한 플러그인입니다.실행 시 과도 의존 관계의 일부로서, 결국에 끌어당기게 됩니다.org.slf4j:slf4j-log4j12(최소한 5~6개의 다른 전이 의존관계에서 서브 전이 의존관계로 언급되고 있습니다.이 프로젝트는 스프링과 하둡을 사용하고 있기 때문에 부엌 싱크대를 제외한 모든 것이 도입되고 있습니다.아니, 잠깐만...그것도 있어요 : )

글로벌하게 제외합니다.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"
}

제외 규칙에는 다음 두 가지 속성만 있는 것 같습니다.group그리고.module.
따라서 개별 종속성에서만 제외하면 다음과 같은 작업을 수행할 수 있습니다.

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

그러나 위의 구문을 사용해도 임의 속성을 술어로 지정할 수 있습니다.개별 종속성에서 제외하려는 경우 임의 속성을 지정할 수 없습니다.예를 들어, 다음과 같이 실패합니다.

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

즉, confirm과 dependency를 지정할 수 있는 경우에도group:그리고.name:제외를 지정할 수 없습니다.name:!?!

아마도 별개의 질문일 것입니다만, 그렇다면 모듈이란 정확히 무엇입니까?groupId:artifactId:version의 Maven 개념을 이해할 수 있습니다.이 개념은 Gradle의 group:name:version으로 번역됩니다.그러면 특정 Maven 아티팩트가 어떤 모듈(그래들 스피크)에 속하는지 어떻게 알 수 있을까요?

하나 이상의 라이브러리를 글로벌하게 제외하려면 다음 항목을 build.gradle에 추가합니다.

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

이제 제외 블록에는 2개의 속성 그룹과 모듈이 있습니다.maven background에서 온 사용자의 경우 groupId와 module은 artifictId동일합니다.예:com.mchange를 제외하려면 c3p0:0.9.2.1을 제외 블록으로 해야 합니다.

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

에 따라서는, .configurations.all { exclude ... }.) 이러한 제외로 여러 의존관계가 제외된 경우(사용 시 전혀 눈치채지 못했습니다), 이상적으로는 재현 가능한 예를 사용하여 http://forums.gradle.org에 버그를 제출해 주십시오.

아래 예에서는 제외합니다.

용수철 부츠

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

스프링 부트 1.5.10을 사용하고 있었는데 로그백을 제외하려고 합니다.상기의 솔루션은 정상적으로 동작하지 않습니다.대신 설정을 사용하고 있습니다.

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

@berguiga-mohamed-amine이 기술한 것 외에 와일드카드에서는 module 인수를 빈 문자열로 남겨야 합니다.

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

compile는 폐지되고, 되었습니다.implementation따라서 새로운 버전의 gradle을 실행하는 사용자를 위한 솔루션은 다음과 같습니다.

implementation("org.springframework.boot:spring-boot-starter-web") {
     exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat' 
}

이것은 Kotlin DSL(build.gradle.kts)용입니다.이것에 의해서, 잘못된 속성을 사용할 수 없게 됩니다.

설정에서 합니다(「」).implementation,runtimeOnly 개요:

configurations.all {
    exclude(group = "ir.mahozad.android", module = "pie-chart")
    // OR exclude("ir.mahozad.android", "pie-chart")
}

// Another notation:
// configurations {
//     all {
//         exclude(group = "ir.mahozad.android", module = "pie-chart")
//     }
// }

예: " " " " " " ) 。implementation

configurations.implementation {
    exclude(group = "ir.mahozad.android", module = "pie-chart")
}

// Another notation:
// configurations {
//     implementation {
//         exclude(group = "ir.mahozad.android", module = "pie-chart")
//     }
// }

단일 종속성에 대한 라이브러리 제외:

dependencies {
    // ...
    implementation("ir.mahozad.android:charts:1.2.3") {
        exclude(group = "ir.mahozad.android", module = "pie-chart")
    }
}

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

반응형