You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Alexander Hars <do...@inventivio.com> on 2005/11/06 17:39:42 UTC

[m2] assembly:directory problem (DirectoryMojo)

Hi,

The assembly:directory goal can be used to simply copy files and 
dependencies into some target directory without packing into a jar or zip.
This is useful when we have custom plugins that need to do some special 
processing on certain files/directories.
However, in the current version of the DirectoryMojo the files can only 
be copied into a *version-dependent* subdirectory of the \target directory.
This happens, because DirectoryMojo is not aware when the 
<includeBaseDirectory>  parameter is set to false.

For example, if my artifact is
<artifactId>myArtifact</artifactId>
<version>1.0</version>,

and my assembly.xml is something like:

<assembly>
<id>someId</id>
..
<outputDirectory>/test</outputDirectory>
..
</assembly>

the resulting files will appear in:
 \target\myArtifact-1.0-someId\myArtifact-1.0\test\*.*

This is unfortunate, because when the version changes, the directory to 
which the files are copied also changes. If we have some other plugins 
that do something with the files copied by assembly:directory, then they 
may not be aware of the directory change.

Fortunately, the assembly plugin has an optional <includeBaseDirectory> 
parameter (defaults to true). This tag allows us to specify that we 
don't want to include the version-dependent base directory.

But if we set <includeBaseDirectory>false</includeBaseDirectory> the 
resulting files will still appear in:
 \target\my-Artifact-1.0-someId\test\*.*

Thus currently there is no way to get the files to be copied to the 
version-independent directory:
\target\test\*.*

Fortunately, there is a simple way to change this: we just need to 
change 1 line in DirectoryMojo.java:

/maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/DirectoryMojo.java

Line 42
-         String fullName = finalName + "-" + assembly.getId();
------------------------------------------------------------------------------------------------------------
+         String fullName = (assembly.isIncludeBaseDirectory() ? 
finalName + "-" + assembly.getId() : "");

(The finalName is the ArtifactId+Version-Number)

-Alexander




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: [m2] assembly:directory problem (DirectoryMojo)

Posted by Anuerin Diaz <ra...@gmail.com>.
hi,

   i have a need similar to what alexander wrote but for a different
reason. the artifacts in my project are distributed as separate jars
files and on a specific directory structure. is there a way to really
specify how the recipient directory is structured in the assembly
configuration file? or do i really need to resort to a custom plugin,
or an ant call?

ciao!

On 11/6/05, Kenney Westerhof <ke...@apache.org> wrote:
> On Sun, 6 Nov 2005, Alexander Hars wrote:
>
> This fixes your issue, but it's not meant for that - you now get all files
> directly in the target/ dir without a common parent dir ( i think ).
>
> Sounds like you want your plugins to run in the process-resources etc.
> phase, and you're just abusing the assembly:directory mojo for copying
> files. I think you're better off including some file copying or just
> processing in your custom plugins. Lots of examples on how to copy files
> in the other plugins.
>
> -- Kenney
>
> > Hi,
> >
> > The assembly:directory goal can be used to simply copy files and
> > dependencies into some target directory without packing into a jar or zip.
> > This is useful when we have custom plugins that need to do some special
> > processing on certain files/directories.
> > However, in the current version of the DirectoryMojo the files can only
> > be copied into a *version-dependent* subdirectory of the \target directory.
> > This happens, because DirectoryMojo is not aware when the
> > <includeBaseDirectory>  parameter is set to false.
> >
> > For example, if my artifact is
> > <artifactId>myArtifact</artifactId>
> > <version>1.0</version>,
> >
> > and my assembly.xml is something like:
> >
> > <assembly>
> > <id>someId</id>
> > ..
> > <outputDirectory>/test</outputDirectory>
> > ..
> > </assembly>
> >
> > the resulting files will appear in:
> >  \target\myArtifact-1.0-someId\myArtifact-1.0\test\*.*
> >
> > This is unfortunate, because when the version changes, the directory to
> > which the files are copied also changes. If we have some other plugins
> > that do something with the files copied by assembly:directory, then they
> > may not be aware of the directory change.
> >
> > Fortunately, the assembly plugin has an optional <includeBaseDirectory>
> > parameter (defaults to true). This tag allows us to specify that we
> > don't want to include the version-dependent base directory.
> >
> > But if we set <includeBaseDirectory>false</includeBaseDirectory> the
> > resulting files will still appear in:
> >  \target\my-Artifact-1.0-someId\test\*.*
> >
> > Thus currently there is no way to get the files to be copied to the
> > version-independent directory:
> > \target\test\*.*
> >
> > Fortunately, there is a simple way to change this: we just need to
> > change 1 line in DirectoryMojo.java:
> >
> > /maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/DirectoryMojo.java
> >
> > Line 42
> > -         String fullName = finalName + "-" + assembly.getId();
> > ------------------------------------------------------------------------------------------------------------
> > +         String fullName = (assembly.isIncludeBaseDirectory() ?
> > finalName + "-" + assembly.getId() : "");
> >
> > (The finalName is the ArtifactId+Version-Number)
> >
> > -Alexander
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
>
> --
> Kenney Westerhof
> http://www.neonics.com
> GPG public key: http://www.gods.nl/~forge/kenneyw.key
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


--

"Programming, an artform that fights back"

Anuerin G. Diaz
Registered Linux User #246176
Friendly Linux Board @ http://mandrivausers.org/index.php
http://capsule.ramfree17.org , when you absolutely have nothing else
better to do

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: [m2] assembly:directory problem (DirectoryMojo)

Posted by Kenney Westerhof <ke...@apache.org>.
On Sun, 6 Nov 2005, Alexander Hars wrote:

This fixes your issue, but it's not meant for that - you now get all files
directly in the target/ dir without a common parent dir ( i think ).

Sounds like you want your plugins to run in the process-resources etc.
phase, and you're just abusing the assembly:directory mojo for copying
files. I think you're better off including some file copying or just
processing in your custom plugins. Lots of examples on how to copy files
in the other plugins.

-- Kenney

> Hi,
>
> The assembly:directory goal can be used to simply copy files and
> dependencies into some target directory without packing into a jar or zip.
> This is useful when we have custom plugins that need to do some special
> processing on certain files/directories.
> However, in the current version of the DirectoryMojo the files can only
> be copied into a *version-dependent* subdirectory of the \target directory.
> This happens, because DirectoryMojo is not aware when the
> <includeBaseDirectory>  parameter is set to false.
>
> For example, if my artifact is
> <artifactId>myArtifact</artifactId>
> <version>1.0</version>,
>
> and my assembly.xml is something like:
>
> <assembly>
> <id>someId</id>
> ..
> <outputDirectory>/test</outputDirectory>
> ..
> </assembly>
>
> the resulting files will appear in:
>  \target\myArtifact-1.0-someId\myArtifact-1.0\test\*.*
>
> This is unfortunate, because when the version changes, the directory to
> which the files are copied also changes. If we have some other plugins
> that do something with the files copied by assembly:directory, then they
> may not be aware of the directory change.
>
> Fortunately, the assembly plugin has an optional <includeBaseDirectory>
> parameter (defaults to true). This tag allows us to specify that we
> don't want to include the version-dependent base directory.
>
> But if we set <includeBaseDirectory>false</includeBaseDirectory> the
> resulting files will still appear in:
>  \target\my-Artifact-1.0-someId\test\*.*
>
> Thus currently there is no way to get the files to be copied to the
> version-independent directory:
> \target\test\*.*
>
> Fortunately, there is a simple way to change this: we just need to
> change 1 line in DirectoryMojo.java:
>
> /maven/components/trunk/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/DirectoryMojo.java
>
> Line 42
> -         String fullName = finalName + "-" + assembly.getId();
> ------------------------------------------------------------------------------------------------------------
> +         String fullName = (assembly.isIncludeBaseDirectory() ?
> finalName + "-" + assembly.getId() : "");
>
> (The finalName is the ArtifactId+Version-Number)
>
> -Alexander
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>

--
Kenney Westerhof
http://www.neonics.com
GPG public key: http://www.gods.nl/~forge/kenneyw.key

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org