On 04/06/07, John Casey <[EMAIL PROTECTED]> wrote:

Hi,

You actually can bind the assembly plugin to two different phases of
the lifecycle, or even twice to the same phase. The key is to use the
<plugin><executions /> block, rather than re-declare the plugin
again. Below, you have two executions declared...you just need to put
them in the same plugin section, and move the <configuration />
blocks into their corresponding <execution /> section.

One thing I will say, though, is that it may make more sense to wrtie
a custom plugin that would use Maven to resolve the dependencies and
inject them into your plugin, then iterate through them, grabbing any
embedded resources that you need along the way. Then, when you've got
all of the resources aggregated and ready to go, you can use the
assembly plugin to package it all up. FWIW, I've been thinking for
awhile now about creating some formal extension points in the
assembly plugin, that would allow you to do this sort of aggregation
during the normal course of the assembly process. Unfortunately, it's
not in place yet. :-(



Hi John,

Thanks for your response. I've got the multi-module approach in place and
working currently, but it's good to know where I was going wrong, and I
think I'll migrate to the suggested approach since it will make the
structure simpler.
I thought about a custom plugin, but time constraints and not having any
other compelling reason to learn the API stopped me!

Cheers,

James

HTH,

-john



On Jun 4, 2007, at 5:53 AM, James Abley wrote:

> On 04/06/07, James Abley <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> I am trying to create an assembly that I can deploy to our
>> internal repository.
>>
>> The envisaged steps in this process are:
>>
>> 1) Get all of the dependencies.
>> 2) Do some final packaging; e.g. consolidate all SQL creation scripts
>> into a single script.
>> 3) Create a zip file ready for deployment.
>>
>> I'm trying to work out the best way of structuring the module
>> responsible for doing this.
>>
>> Can I do it all in a single module, by binding different plugins to
>> the appropriately sequenced phase?
>>
>> e.g.
>>
>> 1) Use maven-assembly-plugin bound to compile to create a temporary
>> working directory of all of the dependencies.
>> 2) Use maven-antrun-plugin bound to test to do the final packaging.
>> 3) Use the maven-assembly-plugin bound to package to create a zip
>> file.
>>
>> Does this sound reasonable / feasible, should I be looking at
>> multiple
>> modules straight away or some other approach?
>
> It doesn't look like I can do this in one step. I can't declare the
> maven-assembly-plugin twice in the same pom - it doesn't see the
> second assembly descriptor.
>
>    <build>
>        <plugins>
>            <!-- Get all of the dependencies for the installer -->
>            <plugin>
>                <artifactId>maven-assembly-plugin</artifactId>
>                <configuration>
>                    <appendAssemblyId>false</appendAssemblyId>
>                    <descriptors>
>                        <descriptor>
>                            src/main/assembly/dep.xml
>                        </descriptor>
>                    </descriptors>
>                </configuration>
>                <executions>
>                    <execution>
>                        <id>create-directories</id>
>                        <phase>compile</phase>
>                        <goals>
>                            <goal>directory-inline</goal>
>                        </goals>
>                    </execution>
>                </executions>
>            </plugin>
>            <plugin>
>                <!-- Do any final packaging tasks. -->
>                <artifactId>maven-antrun-plugin</artifactId>
>                <executions>
>                    <execution>
>                        <!--
>                            this needs to get executed before the
> final assembly plugin.
>                        -->
>                        <phase>test</phase>
>                        <goals>
>                            <goal>run</goal>
>                        </goals>
>                        <configuration>
>                            <tasks>
>                                <!-- Create single DDL file for each
> database vendor -->
>                                <ant
>                                    antfile="${basedir}/src/main/ant/
> ddl.xml"
>                                    inheritRefs="true">
>                                    <property
>
> name="mpinstall.dependencies.dir"
>
> value="${project.build.directory}/${project.build.finalName}.dir" />
>                                </ant>
>                            </tasks>
>                        </configuration>
>                    </execution>
>                </executions>
>                <dependencies>
>                    <dependency>
>                        <!-- Include for <echoproperties/> -->
>                        <groupId>org.apache.ant</groupId>
>                        <artifactId>ant-nodeps</artifactId>
>                        <version>1.7.0</version>
>                    </dependency>
>                </dependencies>
>            </plugin>
>            <plugin>
>                <artifactId>maven-assembly-plugin</artifactId>
>                <configuration>
>                    <descriptor>
>                        src/main/assembly/package.xml
>                    </descriptor>
>                </configuration>
>                <executions>
>                    <execution>
>                        <id>make-assembly</id>
>                        <!--
>                            append to the packaging phase. This will
> let us
>                            deploy the zip file to the internal
> repository
>                            sites.
>                        -->
>                        <phase>package</phase>
>                        <goals>
>                            <goal>attached</goal>
>                        </goals>
>                    </execution>
>                </executions>
>            </plugin>
>        </plugins>
>    </build>
>
>
> The second use of the maven-assembly-plugin shows that it is using the
> descriptor src/main/assembly/dep.xml again, which isn't what I want.
> That means that it misses out the changes done in the ANT target which
> is the point of splitting out the process into more steps.
>
> If I don't declare the plugin twice and instead specify two
> descriptors in the single maven-assembly-plugin declaration, how do I
> ensure that the correct descriptor is used at the correct time?
>
>
>
> So I tried the other way of splitting it out into multiple modules:
>
> I have one module that draws in all the dependencies and does the
> inline-directory thing prior to using ANT to do some other stuff, and
> then have a second module which uses a fileset to reference the
> artifacts generated by the first assembly plugin / ANT combination.
>
> This seems to do more or less what I want, but the baseDirectory of
> the resulting zip is not what is required.
>
> e.g.
>
> MyProject module containing MyProject-dependencies and
> MyProject-packaging modules.
>
> ls  MyProject-dependencies/target/MyProject-dependencies-finalName
>
> wars
> db
> docs
>
> (Looks good.)
>
> unzip -l MyProjectp-packaging/target/MyProject-packaging-finalName.zip
> ../MyProject-dependencies/target/MyProject-dependencies-finalName/wars
> ./MyProject-dependencies/target/MyProject-dependencies-finalName/db
> ./MyProject-dependencies/target/MyProject-dependencies-finalName/docs
>
> (I don't want that MyProject-dependencies/target prefix here!)
>
> How best to get rid of the ../MyProject-dependencies/target directory?
> My initial reaction is to use another ANT task before the final zip to
> copy the content into MyProject-packaging, maybe do the zip in ANT if
> I need that level of control and use a <files/> element in the
> assembly descriptor.
>
> That would seem like not the Maven way. Any other suggestions?
>
> Cheers,
>
> James
>
>>
>> Cheers,
>>
>> James
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>

---
John Casey
Committer and PMC Member, Apache Maven
mail: jdcasey at commonjava dot org
blog: http://www.ejlife.net/blogs/john



Reply via email to