maven сборка игнорирует родительские зависимости
-
06-07-2019 - |
Вопрос
Мой дескриптор сборки применяет включения и исключения правильно, когда зависимости включаются в файл pom напрямую.
Однако, когда я помещаю зависимости в родительский pom-файл, сборка: цель каталога сообщает, что включения и исключения не сработали.
Знаете ли вы, почему maven-assembly-plugin игнорирует родительские зависимости? Как я могу это исправить?
Вот дескрипторы maven и ассемблера:
Дескриптор сборки:
<assembly>
<id>distribution</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<includes>
<include>readme.txt</include>
</includes>
</fileSet>
<fileSet>
<directory>target</directory>
<outputDirectory>/lib</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>/lib</outputDirectory>
<unpack>false</unpack>
<scope>runtime</scope>
<excludes>
<exclude>org.tanukisoftware:wrapper:exe:3.3.5</exclude>
</excludes>
</dependencySet>
<dependencySet>
<outputDirectory>/bin</outputDirectory>
<unpack>false</unpack>
<scope>runtime</scope>
<includes>
<include>org.tanukisoftware:wrapper:exe:3.3.5</include>
</includes>
</dependencySet>
</dependencySets>
</assembly>
Определение плагина дочерней POM-сборки:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<ignoreDirFormatExtensions>true</ignoreDirFormatExtensions>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>directory</goal>
</goals>
</execution>
</executions>
</plugin>
Родительские зависимости POM:
<dependencies>
<dependency>
<groupId>org.tanukisoftware</groupId>
<artifactId>wrapper</artifactId>
<version>3.3.5</version>
<type>dll</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.tanukisoftware</groupId>
<artifactId>wrapper</artifactId>
<version>3.3.5</version>
<type>exe</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.tanukisoftware</groupId>
<artifactId>wrapper</artifactId>
<version>3.3.5</version>
<scope>runtime</scope>
</dependency>
</dependencies>
Предупреждения в отчете о сборке:
[assembly:directory {execution: make-assembly}]
Reading assembly descriptor: assembly.xml
Processing DependencySet (output=/lib)
[WARNING] The following patterns were never triggered in this artifact exclusion filter:
o 'org.tanukisoftware:wrapper:exe:3.3.5'
Processing DependencySet (output=/bin)
[WARNING] The following patterns were never triggered in this artifact inclusion filter:
o 'org.tanukisoftware:wrapper:exe:3.3.5'
Решение
Я не знаю, поможет ли это, но то, что я всегда делаю, - это в родительском помете помещаю зависимости в блок зависимостей;
<dependencyManagement>
<!-- dependencies with exclusions -->
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${version.springframework}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
Затем в дочернем pom снова перечислите зависимости, но без версии и исключений
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</dependency>
Но, честно говоря, для моей первой и единственной сборки я не мог заставить его работать в дочернем модуле и поместить его в родительский модуль. Вот мой сборочный файл для создания zip-файла для отдельной Java-программы, запускаемой cron:
<?xml version="1.0" encoding="UTF-8"?>
<assembly>
<id>${project.layer}-both</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<baseDirectory>/</baseDirectory>
<moduleSets>
<moduleSet>
<includes>
<include>edu.berkeley.ist.cars:cars_upload</include>
</includes>
<binaries>
<unpack>false</unpack>
<useStrictFiltering>true</useStrictFiltering>
<includeDependencies>true</includeDependencies>
<outputDirectory>upload</outputDirectory>
</binaries>
</moduleSet>
<moduleSet>
<includes>
<include>edu.berkeley.ist.cars:cars_download</include>
</includes>
<binaries>
<unpack>false</unpack>
<useStrictFiltering>true</useStrictFiltering>
<includeDependencies>true</includeDependencies>
<outputDirectory>download</outputDirectory>
</binaries>
</moduleSet>
</moduleSets>
<!--
crontab.txt is put in twice, in both upload and download, just in case.
-->
<files>
<!-- upload files -->
<file>
<source>src/stuff/scripts/cars_upload.sh</source>
<lineEnding>unix</lineEnding>
<filtered>true</filtered>
<outputDirectory>upload</outputDirectory>
</file>
<file>
<source>src/stuff/notes/crontab-${project.layer}.txt</source>
<destName>crontab.txt</destName>
<lineEnding>unix</lineEnding>
<filtered>true</filtered>
<outputDirectory>upload</outputDirectory>
</file>
<!-- download files -->
<file>
<source>src/stuff/scripts/cars_download.sh</source>
<lineEnding>unix</lineEnding>
<filtered>true</filtered>
<outputDirectory>download</outputDirectory>
</file>
<file>
<source>src/stuff/notes/crontab-${project.layer}.txt</source>
<destName>crontab.txt</destName>
<lineEnding>unix</lineEnding>
<filtered>true</filtered>
<outputDirectory>download</outputDirectory>
</file>
</files>
</assembly>
В zip-файле есть две директории верхнего уровня: выгрузка и загрузка.