Maven: How to unpack precise files from artifacts in the same output directory?

Rémi Doolaeghe

I have several artifacts from the same groupId (org.webjars), and I need to unpack them, and then copy all the contained js files into the same directory.

The artifacts archives have a hierarchy (compressed as a jar) as follows:

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

I need at the end that every js file is copied into the same directory without their hierarchy, as follows:

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

The result I can reach is the following one:

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

For this purpose, I used the 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>

Is there a magical option of this plugin to do this, or should I need another plugin to complete the job?

EDIT: Here is the solution I finally used:

<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>
Aurélien Bourdon

You could use the maven antrun plugin by using the copy task with the flatten option as it is described in the following thread: Maven : copy files without subdirectory structure

Best

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to unpack just the files from a sub-folder in maven-dependency-plugin with goal unpack-dependencies?

Unpack files from jar if jar is used, copy then extracted files to a directory

How to add files from S3 bucket to output artifacts in AWS CodePipeline? (NodeJS)

Is it possible to output and rename build artifacts from the TeamCity checkout directory (that are not archives)?

Maven and java: how to generate code from protobuf files in test directory?

How to output files without extension from external storage directory?

How to include files from same directory in a module using Cargo/Rust?

How to copy multiple files with a same name from children directory to another directory without losing the parent directory?

Python - Create output files from an input file that has the same name as it for all file in a directory

Moving Files From Libraries to Output Directory Not working

How to unpack the group_by() do() output from dplyr pipe

How to move files from subdirectories that have the same directory name to its relative upper/parent directory?

import files from same directory in VSCode

How can I simultaneously extract files from .tar files and send them to the same directory?

How to copy 700 files + 80 files into two different directory from same source, using loop in Python?

Why are there no files in my release artifacts directory?

How to output files to another directory (Poppler - pdftotext)

Maven missing artifacts but files are in place - Eclipse

gulp-typescript with gulp-sourcemap: output files to same directory

Webpack output all the files within a directory with the same name into a different folder

How to sync files in directory a from directory b?

How to add files from webapp directory to jar using Maven Assembly plugin?

How to copy all files in same directory as gulpfile?

How to remove the same size files in a directory?

How to rename multiple files in a directory at the same time

how to load files dynamically in the same directory python

Maven project is not able to download artifacts from Azure Artifacts

Pull all artifacts from Maven Artifactory instead of just JAR artifacts

How to get more precise output out of an FFT?