phatmanace
phatmanace

Reputation: 5021

maven assembly plugin: control over directories

I'm trying to convert some groovy (gradle) code to maven. Where possible, we're trying to use off-the-shelf plugins rather than custom ones.

We wanted to use the maven assembly plugin to assemble a tar file that we'll use for deployment. The directory structure is important for our deployment tools, and I seem to be fighting against getting maven to get it to do what I want.

The key problem on the bottom code snippet is the fact that the jar ended up in a target directory in the tar file. My question is: can this be avoided? or should I cut my losses and write a simple custom plugin to do this?

(its possible I'm putting 2 and 2 together and getting 5, but it does seem related to this bug here)

Directory structure (After running the build)

.
└── project1
    ├── config
    │   └── foo.config
    ├── pom.xml
    ├── src
    │   └── main
    │       ├── assembly
    │       │   └── assembly.xml
    │       └── java
    │           └── com
    │               └── foo
    │                   └── bar
    │                       └── App.java
    └── target
        ├── archive-tmp
        ├── classes
        │   └── App.class
        ├── maven-archiver
        │   └── pom.properties
        ├── my-static-jar-name-bundle.tar
        └── my-static-jar-name.jar

Assembly file

<assembly>
    <id>bundle</id> 
    <formats>
        <format>tar</format>
    </formats>
<includeBaseDirectory>false</includeBaseDirectory>

    <fileSets>
        <fileSet>
            <directory>${basedir}</directory>
            <outputDirectory>/spooge</outputDirectory>
        <includes>
                <include>**/*.jar</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>${project.basedir}/config</directory>
            <outputDirectory>appconfig</outputDirectory>
        <includes>
                <include>**/*.config</include>
            </includes>
        </fileSet>
</fileSets>
</assembly>

contents of the tar file when the build has finished (note the jar is in a 'target' subfolder)

tar xvf project1/target/my-static-jar-name-bundle.tar 
x spooge/target/my-static-jar-name.jar
x appconfig/foo.config

Upvotes: 1

Views: 1357

Answers (1)

user944849
user944849

Reputation: 14951

Try changing the fileset as shown:

<fileSet>
    <directory>${project.build.directory}</directory>
    <outputDirectory>/spooge</outputDirectory>
    <includes>
        <include>**/*.jar</include>
    </includes>
</fileSet>

The way it's currently configured, the assembly plugin is searching project1s entire directory for any jar files. The only one it finds is in the target directory, so Maven happily includes it in the tar. The change I suggest uses project1/target as the starting point, so I think you'll get the result you want.

Upvotes: 1

Related Questions