views:

42

answers:

2

I'm trying to setup my maven build to copy all the build artifacts and other generated files to a central directory for distribution. After reading docs, the assembly plugin and the dependency plugin seem to be the ones to use. but I cant get them to play well together.

first - If I follow the directions here and add this to my top level pom:

<plugin>  
  <groupId>org.apache.maven.plugins</groupId>  
  <artifactId>maven-dependency-plugin</artifactId>  
  <executions>  
    <execution>  
      <id>copy-installed</id>  
      <phase>install</phase>  
      <goals>  
        <goal>copy</goal>  
      </goals>  
      <configuration>  
        <artifactItems>  
          <artifactItem>  
            <groupId>${project.groupId}</groupId>  
            <artifactId>${project.artifactId}</artifactId>  
            <version>${project.version}</version>
            <type>${project.packaging}</type>
          </artifactItem>
        </artifactItems>
        <outputDirectory>${ReleaseFolder}</outputDirectory>
      </configuration>
    </execution>
  </executions>
</plugin>

all seems fine until I run a clean followed by an install - then maven complains it cant find my top level pom to install. which seems counter-intuitive... i wont want the "pom" files to be copied, i want the module artifacts. How do I exclude them?

And related to this - is there a way to add custom types or tags of some kind to projects so i can have the dependancy copy work one way on one type of sub-project and a diferent way on another type?

new to maven -- so please be gentle.

edit: My project structure looks something like so:

/pom.xml (top level pom)
Common_data
ComponentA
ComponentB
ComponentC
ComponentT (depends on A, B and C)
J2ee_A
    j2ee_A_ear (depends on war)
    j2ee_A_rar
    j2ee_A_war

J2ee_B 
    j2ee_B_ear (depends on war)
    j2ee_B_rar
    j2ee_B_war
    j2ee_B_jar (depends on ComponentB)

and then ${ReleaseFolder} points to /Release at the same level as the top level pom.

Follow-up: So what im hearing is dependency:copy is not the route to go, but using an assembly is.

How do I get an assembly to operate on many different modules and then copy the resulting files to a single output directory?

To add to things - there are 2 general types of components, a jar component (makes a single jar file), and a j2ee component which produces, ear, war, jar, rar and config files.

If there was a way to assign my own tags to a project and then run an assembly based on that tag value, I can see that working. But I havent found anything in the documentation on how to trigger or skip an assembly based on user defined properties in a sub-project.

Ideas anyone?

A: 

I think you may have the cart before the horse here. You're asking dependency:copy to go to the repository (that's what copy does) to get your artifact. However, you're still in the install phase, so your artifact may not yet be in the repository.

Anyway, getting access to your build artifact this way is somewhat unconventional. Is there any reason you can't just go grab target/foo.jar, since you know based on Maven directory conventions where you artifact will be after the package phase?

RonU
so dependency:copy goes to the repository FIRST? ... the documentation doesnt make that clear. but it kindof explains why im having the problem. I also found if I changed the dependency:copy goal to run in the install phase, then the error went away.
Jon
well the reason i went with the dependency copy is the resulting project will proably be several levels deep with 100+ artifacts when all is done, and I want to keep the release management as simple as feasable when things change. So when a componet is added/removed there should be only minor changes to the project's structure. or is that an unreasonable expectation?
Jon
I tried using the assembly plugin, but there didnt seem to be a way to copy the build artifacts from multiple sub-projects to a `single` output directory - unless im missing something fundamental here.
Jon
Can't be it. First, the OP described a problem after a `clean`, not a purge of the repository. Second, the goal `dependency:copy` is bound to `install` and will thus occur after the artifact has been installed (so it will be present in the repository).
Pascal Thivent
okay - it seems im asking the wrong question here. i'll submit a new question.
Jon
+1  A: 

I tried using the assembly plugin, but there didn't seem to be a way to copy the build artifacts from multiple sub-projects to a single output directory - unless I'm missing something fundamental here.

In my opinion, you should NOT introduce tight coupling between all your modules and you should thus NOT grab things directly from target as someone suggested, doing this is fundamentally wrong.

What you're describing here is definitely doable with the Maven Assembly plugin and one good way to implement this would be to create a dedicated distribution project module, to declare dependencies on other modules in its POM and to use dependencySets in a custom assembly descriptor.

Something like this for the structure:

.
|-- pom.xml (top level pom)
|-- Common_data
|-- ComponentA
|-- ComponentB
|-- ComponentC
|-- ComponentT (depends on A, B and C)
|-- J2ee_A
|   |-- j2ee_A_ear (depends on war)
|   |-- j2ee_A_rar
|   `-- j2ee_A_war
|-- J2ee_B 
|   |-- j2ee_B_ear (depends on war)
|   |-- j2ee_B_rar
|   |-- j2ee_B_war
|   `-- j2ee_B_jar (depends on ComponentB)
`-- distro
    |-- pom.xml
    `-- src
        `-- main
            `-- assembly
                `-- myassembly.xml

And for the assembly descriptor, have a look at the section 8.6. Best Practices of the Maven Book, they describe this approach and provide an assembly descriptors sample. Adapt it to fit your needs, to use a dir format instead of an archive format. It's a good starting point.

Resources

References

Pascal Thivent
okay this is a good start.
Jon
Ive taken a good look at the assembly descriptor and the dependencySets entries - but I can never seem to get it to "find" any of my modules - either by direct reference: `<include>myCompany:j2ee_A.ear:ear</include>` which gives "cannot resolve component" errors -- or by attempting to include everything. I understand the distro pom must have dependencies on the modules I want to include - but that never seems to have an effect (nothing is included in the output). The assembly assembly needs to work for "n" number of jar components and/or "n" number of j2ee components.
Jon
Any suggestions on how to start on such an assembly? .. Pascal's advice is what im after, I want loose coupling wherever possible.
Jon
@Jon I think I'll try to answer the other question... Might be easier as you're providing a project structure.
Pascal Thivent