Question

I would be pleasant, if you could help me to figure out this problem.

When I build my project to .zip with maven <assembly> plugin.

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">

<id>dev</id>
<formats>
    <format>zip</format>
</formats>

<fileSets>

    <fileSet>
        <directory>${basedir}</directory>
        <includes>
            <include>/environments/dev/**/*.sh</include>
            <include>/environments/dev/**/*.jil</include>
            <include>/environments/dev/**/*.properties</include>
            <include>/environments/dev/**/log4j2.xml</include>  
        </includes>  
    </fileSet>

</fileSets>

<dependencySets>
    <dependencySet>
        <outputDirectory>/lib</outputDirectory>
        <useProjectArtifact>true</useProjectArtifact>
        <scope>runtime</scope>
    </dependencySet>
</dependencySets>

I receive the following file structure:

build.zip----> environments__
                            |_DEV_
                                  |_bin
                                  |_properties
                                  |_....

My goal is:

To get the following file structure after maven build:

 build.zip----> 
                                  |_bin
                                  |_properties
                                  |_....

Without environments and DEV folders.

I've read in the maven documentation (http://maven.apache.org/plugins/maven-assembly-plugin/advanced-descriptor-topics.html) that we can exclude some file directories. This way:

<assembly> 
    ....

    <fileSets> 
        <fileSet>
            <directory>${basedir}</directory>
            <includes>
              ....
            </includes>
            <excludes>
                <exclude>/environments/dev</exclude>
            </excludes>
        </fileSet> 
    </fileSets>

    <dependencySets>
        <dependencySet>
            <outputDirectory>/lib</outputDirectory>
            <useProjectArtifact>true</useProjectArtifact>
            <scope>runtime</scope>
        </dependencySet>
    </dependencySets>
</assembly>

But it doesn't help. I still have previous file structure.

Was it helpful?

Solution

You want to set the root of your directory to /environments/dev

<fileSet>
    <directory>${basedir}/environments/dev</directory>
    <outputDirectory>/</outputDirectory>
    <filtered>false</filtered>
</fileSet>

OTHER TIPS

From the documentation of maven-assembly-plugin (maven-assembly-plugin) I can see that the <fileSets> tag does not provide us with the option of changing the path of an included resource. Instead we can use the <file> tag which gives us this flexibility.

For example, the below configuration will include file1.jar and run.bat in the root folder of the extracted zip file, skipping their original paths.

<assembly>
  <formats>
    <format>zip</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <files>
    <file>
      <source>target/file1.jar</source>
      <destName>file1.jar</destName>
    </file>
    <file>
      <source>src/main/resources/run.bat</source>
      <destName>run.bat</destName>
    </file>
  </files>
</assembly>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top