Search code examples
javamavenmaven-assembly-plugin

How to change output directory of moduleSet/sources with maven-assembly-plugin


I want to change the output directory of a moduleSet with maven-assemble-plugin. I tried moduleSet/sources/outputDirectory, but I get a strange zip file.

My descriptor:

<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">

    <id>distribution</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>

    <moduleSets>
        <moduleSet>
            <useAllReactorProjects>true</useAllReactorProjects>
            <excludes>
                <exclude>*:test-distribution</exclude>
            </excludes>
            <sources>
                <includeModuleDirectory>false</includeModuleDirectory>
                <outputDirectory>sources</outputDirectory>
                <fileSets>
                    <fileSet>
                        <includes>
                            <include>src/**</include>
                        </includes>
                    </fileSet>
                </fileSets>
            </sources>
        </moduleSet>
    </moduleSets>
</assembly>

My zip file has following structure:

- test-distribution.zip
    - sources
        - src
             - main
             - test
        - target
        - pom.xml  (of first module)
    - src
        - main
        - test

Under /sources is the hole project instead of only the src folder and under /srcis the source folder.

What I want is:

- test-distribution.zip
    - sources
         - main
         - test

How can I change the name of the directory of moduleSet/sources?


Solution

  • With fileSet/outputDirectory and fileSet/directory it is possible to change the name of the source directory:

    <?xml version="1.0" encoding="UTF-8"?>
    <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
    
        <id>distribution</id>
        <formats>
            <format>zip</format>
        </formats>
        <includeBaseDirectory>false</includeBaseDirectory>
    
        <moduleSets>
            <moduleSet>
                <useAllReactorProjects>true</useAllReactorProjects>
                <excludes>
                    <exclude>*:test-distribution</exclude>
                </excludes>
                <sources>
                    <includeModuleDirectory>false</includeModuleDirectory>
                    <fileSets>
                        <fileSet>
                            <includes>
                                <include>/**</include>
                            </includes>
                            <outputDirectory>sources</outputDirectory>
                            <directory>src</directory>
                        </fileSet>
                    </fileSets>
                </sources>
            </moduleSet>
        </moduleSets>
    </assembly>
    

    But I can't say, what sources/outputDirectory should do. This option is very strange.