Maven: Как распаковать точные файлы из артефактов в том же каталоге вывода?

У меня есть несколько артефактов из той же группыId (org.webjars), и мне нужно их распаковать, а затем скопировать все содержащиеся файлы js в один каталог.

Архивы артефактов имеют иерархию (сжатую как банку) следующим образом:

artifact1
    - resources
        - webjars
            - ...
                - sample-1.js
                - sample-2.js

В конце концов мне нужно, чтобы каждый js файл копировался в тот же каталог без их иерархии, как показано ниже:

outputDirectory
    - sample-1.js
    - sample-2.js
    - ...
    - sample-n.js

Результат, который я могу достичь, следующий:

outputDirectory
    - artifact-1
        - resources
            - webjars
                - ...
                    - sample-1.js
                    - sample-2.js
    - ...
    - artifact-m
        - resources
            - webjars
                - ...
                    - sample-n.js

Для этой цели я использовал maven-dependency-plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>unpack org.webjars dependencies</id>
            <goals>
                <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
            <includeGroupIds>org.webjars</includeGroupIds>
            <includes>**/*.js</includes>
            <outputDirectory>${project.build.directory}/static</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

Есть ли волшебный вариант этого плагина, чтобы сделать это, или мне нужен еще один плагин для выполнения задания?

EDIT: Вот решение, которое я наконец использовал:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
            <id>copy org.webjars dependency to jar</id>
            <phase>package</phase>
            <goals><goal>run</goal></goals>
            <configuration>
                <target>
                    <copy todir="${project.build.directory}/classes/static" flatten="true">
                        <fileset dir="${project.build.directory}/static">
                                     <include name="**/*.js"/>
                        </fileset>
                    </copy>
                </target>
            </configuration>
          </execution>
    </executions>
</plugin>
<!-- Force the generation of the jar to be done after the javascript dependencies have been copied.
Note : This is a half solution, as the jar is generated twice: a first time before the javascript get copied, and
another one after. As a result, there is the correct jar, but after two creations... -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <executions>
        <execution>
            <id>Force the jar-plugin to be called after the javascripts dependencies have been copied to be embedded</id>
            <phase>package</phase>
            <goals><goal>jar</goal></goals>
           </execution>
       </executions>
</plugin>

Ответы

Ответ 2

Возможно, вы сможете немного приблизиться, используя <useSubDirectoryPerArtifact>false</useSubDirectoryPerArtifact>. Но я думаю, что цель unpack-dependencies по-прежнему будет включать полный путь к файлам из артефактов, которые он распаковывает.

Ответ 3

Просто наткнулся на подобную проблему, и (так как я не большой поклонник запуска устаревшего Ant внутри Maven, в этот день и возраст), я закончил использование org.apache.portals.jetspeed-2: jetspeed-unpack-maven-plugin (ссылка mvnrepository здесь). В своем <resource> конфигурации вы можете указать <flat> true </flat> который будет сглаживать структуру каталогов по желанию.