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

From Dev

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

From Dev

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

From Dev

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

From Dev

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

From Java

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

From Dev

How to output files without extension from external storage directory?

From Dev

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

From Dev

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

From Dev

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

From Dev

Moving Files From Libraries to Output Directory Not working

From Dev

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

From Dev

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

From Dev

import files from same directory in VSCode

From Dev

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

From Dev

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

From Dev

Why are there no files in my release artifacts directory?

From Dev

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

From Java

Maven missing artifacts but files are in place - Eclipse

From Dev

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

From Dev

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

From Dev

How to sync files in directory a from directory b?

From Dev

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

From Dev

How to copy all files in same directory as gulpfile?

From Dev

How to remove the same size files in a directory?

From Dev

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

From Dev

how to load files dynamically in the same directory python

From Java

Maven project is not able to download artifacts from Azure Artifacts

From Java

Pull all artifacts from Maven Artifactory instead of just JAR artifacts

From Dev

How to get more precise output out of an FFT?

Related Related

  1. 1

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

  2. 2

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

  3. 3

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

  4. 4

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

  5. 5

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

  6. 6

    How to output files without extension from external storage directory?

  7. 7

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

  8. 8

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

  9. 9

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

  10. 10

    Moving Files From Libraries to Output Directory Not working

  11. 11

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

  12. 12

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

  13. 13

    import files from same directory in VSCode

  14. 14

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

  15. 15

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

  16. 16

    Why are there no files in my release artifacts directory?

  17. 17

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

  18. 18

    Maven missing artifacts but files are in place - Eclipse

  19. 19

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

  20. 20

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

  21. 21

    How to sync files in directory a from directory b?

  22. 22

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

  23. 23

    How to copy all files in same directory as gulpfile?

  24. 24

    How to remove the same size files in a directory?

  25. 25

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

  26. 26

    how to load files dynamically in the same directory python

  27. 27

    Maven project is not able to download artifacts from Azure Artifacts

  28. 28

    Pull all artifacts from Maven Artifactory instead of just JAR artifacts

  29. 29

    How to get more precise output out of an FFT?

HotTag

Archive