부모 POM에서 상속받은 아티팩트를 제외할 수 있는 방법이 있습니까?
로부터의 아티팩트는 "Dependency"를 할 수 .<exclusions>
<dependency>
그러나 이 경우 상위 프로젝트에서 상속된 아티팩트를 제외해야 합니다.POM을 사용하다
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>jruby</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<artifactId>base</artifactId>
<groupId>es.uniovi.innova</groupId>
<version>1.0.0</version>
</parent>
<dependencies>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>ALL-DEPS</artifactId>
<version>1.0</version>
<scope>provided</scope>
<type>pom</type>
</dependency>
</dependencies>
</project>
base
, 의존javax.mail:mail-1.4.jar
, , , , 입니다.ALL-DEPS
동일한 라이브러리의 다른 버전에 따라 다릅니다.같은 라이브러리의 다른 버전에 의존합니다. Due to the fact that 라는 사실 때문에mail.jar
부에서ALL-DEPS
내보내기 환경에서 존재하지 않지만 경 행 에 재 보 지 돌 내충, exist environ않다 the니 exported notment합 on만내는,ides the환존실지만지하 although collmail.jar
that exists on the parent, which is scoped as 부모에 존재하며, 그 부모에 따라 결정됩니다.compile
.
해결책은 부모 POM에서 mail.jar를 삭제하는 것입니다만, 베이스를 상속하는 대부분의 프로젝트에서는 그것이 필요합니다(log4j의 트랜스트레이티브 의존관계).그래서 제가 하고 싶은 일은 단순히 부모 라이브러리를 자녀 프로젝트에서 제외하는 것입니다.base
종속성이었고 부모 포포는 아니다.부모 폼이 아닌 의존관계입니다.
...
<dependency>
<artifactId>base</artifactId>
<groupId>es.uniovi.innova</groupId>
<version>1.0.0</version>
<type>pom<type>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
</exclusions>
</dependency>
...
몇 가지 아이디어:
상속받지 부모로부터 의존을 합니다).
base
폼에 하지 않다.★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★하나 해 볼 은 '알다'를 입니다.
mail
한ALL-DEPS
dependencyManagement
parent pom에서 컨버전스를 강제합니다(이것이 스코핑 문제를 해결할지는 잘 모르겠습니다만).
<dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>???</version><!-- put the "right" version here -->
</dependency>
</dependencies>
</dependencyManagement>
- '나', '나'는 빼고
mail
하여 기능을 log4j에 의존합니다(log4j에 의존합니다).
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
</dependency>
- 또는 이단 버전 1.2.15가 아닌 log4j 버전 1.2.14로 되돌릴 수도 있습니다(위의 종속성을 옵션으로 표시하지 않은 이유는 무엇입니까?).
수 .pom
Sonatypes의 베스트 프랙티스에 기재되어 있습니다.
<project>
<modelVersion>4.0.0</modelVersion>
<artifactId>base-dependencies</artifactId>
<groupId>es.uniovi.innova</groupId>
<version>1.0.0</version>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
</project>
).<type>pom</type>
<project>
<modelVersion>4.0.0</modelVersion>
<artifactId>base</artifactId>
<groupId>es.uniovi.innova</groupId>
<version>1.0.0</version>
<packaging>pom</packaging>
<dependencies>
<dependency>
<artifactId>base-dependencies</artifactId>
<groupId>es.uniovi.innova</groupId>
<version>1.0.0</version>
<type>pom</type>
</dependency>
</dependencies>
</project>
자녀 프로젝트는 이전과 같이 이 부모 pom을 상속합니다.을 상속합니다.은 러나 within within within within within within within within within within within within within within within within 할 수 .dependencyManagement
삭제:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>jruby</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<artifactId>base</artifactId>
<groupId>es.uniovi.innova</groupId>
<version>1.0.0</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<artifactId>base-dependencies</artifactId>
<groupId>es.uniovi.innova</groupId>
<version>1.0.0</version>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
</project>
부모 폼을 사용하지 마세요.
극단적으로 들릴 수도 있지만, 같은 방법으로 "상속 지옥"이 일부 사람들이 객체 지향 프로그래밍을 등지고(또는 상속보다 구성을 선호함) 문제가 있는 것을 제거하는 이유입니다.<parent>
무엇이든 차단하고 복사하여 붙여넣기<dependencies>
(네 팀이 너에게 자유를 준다면) 네가 필요해.
"재사용"과 "용장 방지"를 위해 부모와 자녀로 퐁을 분할한다는 가정은 무시되어야 하며, 즉각적인 필요를 먼저 충족시켜야 합니다(치료법이 질병보다 더 심각합니다).게다가, 중복성에는 그 장점이 있다. 즉, 외부 변화로부터 독립적이다(즉, 안정성).
인 폼에서 생성 을하면 들리는 (이클립스는 폼을 합니다.mvn help:effective
를 참조해 주세요.
예
사용하고 싶다logback
되는데, 에는 slf4j가 되어 있습니다.log4j
가기 아이들의 자기들만의 log4j에 넣어야 요.pom.xml
내 것이 방해받지 않도록 파일을 보관해 주세요.
에서) 을 (POM으로) 재정의합니다.scope
항아리를 : 빈 항아리를 가리키는 시스템.
<dependency>
<groupId>dependency.coming</groupId>
<artifactId>from.parent</artifactId>
<version>0</version>
<scope>system</scope>
<systemPath>${project.basedir}/empty.jar</systemPath>
</dependency>
이 jar에는 빈 파일을 1개만 포함할 수 있습니다.
touch empty.txt
jar cvf empty.jar empty.txt
메일의 버전을 명시적으로 선언해 본 적이 있습니까?항아리 드릴까요?Maven의 의존관계 해결에서는 다른 모든 버전에 대한 의존관계 해결에 이 방법을 사용해야 합니다.
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>jruby</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<artifactId>base</artifactId>
<groupId>es.uniovi.innova</groupId>
<version>1.0.0</version>
</parent>
<dependencies>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>VERSION-#</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>ALL-DEPS</artifactId>
<version>1.0</version>
<scope>provided</scope>
<type>pom</type>
</dependency>
</dependencies>
</project>
가장 좋은 방법은 항상 상속하고 싶지 않은 종속성을 자동화하는 것입니다.
이를 위해서는 부모 폼에 스코프를 지정하여 마킹할 수 있습니다.
의 버전을 는, 「」를 사용해 .<dependencyManagement>
태그를 사용하여 버전을 명시적으로 상속하거나 상속을 자녀에게 전달하지 않고 원하는 버전을 설정할 수 있습니다.
난 정말 더러운 일을 해야 했어...방법은 다음과 같습니다
는 그 했다.test
.범위provided
효과가 없었습니다.
우리는 fat jar를 만들기 위해 spring boot 플러그인을 사용합니다.공통 라이브러리를 정의하는 모듈 공통(예: Springfox swagger-2)이 있습니다.슈퍼서비스는 부모공통이 필요합니다(그렇게 하고 싶지 않지만 회사규칙에 의해 강제됩니다.
그래서 부모님이나 집 사람들은 폼을 가지고 있다.
<dependencyManagement>
<!- I do not need Springfox in one child but in others ->
<dependencies>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-bean-validators</artifactId>
<version>${swagger.version}</version>
</dependency>
<!- All services need them ->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${apache.poi.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
그리고 나의 슈퍼 서비스 폼.
<name>super-service</name>
<parent>
<groupId>com.company</groupId>
<artifactId>common</artifactId>
<version>1</version>
</parent>
<dependencies>
<!- I don't need them ->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-bean-validators</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-core</artifactId>
<version>2.8.0</version>
<scope>test</scope>
</dependency>
<!- Required dependencies ->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
</dependency>
</dependencies>
이것은 최종 지방 유물의 크기입니다.
82.3 MB (86,351,753 bytes) - redefined dependency with scope test
86.1 MB (90,335,466 bytes) - redefined dependency with scope provided
86.1 MB (90,335,489 bytes) - without exclusion
또한 이 답변은 언급할 가치가 있다 - 그렇게 하고 싶었지만, 나는 게을러서...https://stackoverflow.com/a/48103554/4587961
parent pom을 type pom과의 의존관계로 추가하여 제외할 수 있습니다.왜냐하면 어쨌든 parent pom이 다운로드 되어있기 때문이다.이건 내게 효과가 있었다.
<dependency>
<groupId>com.abc.boot</groupId>
<artifactId>abc-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<type>pom</type>
<exclusions>
<exclusion>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</exclusion>
</exclusions>
</dependency>
하위 pom.xml에서 부모 종속성을 반복하고 제외 항목을 삽입합니다.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
</exclusion>
</exclusions>
</dependency>
패키지를 호출하지만 종속성을 원하지 않는 경우 다음과 같은 작업을 수행할 수 있습니다(이 경우 새 log4j를 사용해야 하므로 이전 log4j를 추가하지 않았습니다).
<dependency>
<groupId>package</groupId>
<artifactId>package-pk</artifactId>
<version>${package-pk.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- LOG4J -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.5</version>
</dependency>
난 이거면 되는데...java/maven은 처음이라 최적은 아닐지도 모릅니다.
상위에서 상속된 하위 아티팩트 사용 안 함
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
상위에서 특정 아티팩트 제거
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
언급URL : https://stackoverflow.com/questions/2681759/is-there-anyway-to-exclude-artifacts-inherited-from-a-parent-pom
'it-source' 카테고리의 다른 글
엔티티 프레임워크 MariaDb 문자열 날짜 문제 (0) | 2022.12.19 |
---|---|
동일한 서버에서 MySQL 데이터베이스를 복제하는 방법 (0) | 2022.12.19 |
크리스마스 트리는 어떻게 감지하나요? (0) | 2022.12.19 |
Spring-Data-JPA 주석을 위한 setMaxResults? (0) | 2022.12.19 |
행별로 반복하면서 판다의 데이터 프레임 업데이트 (0) | 2022.12.19 |