开发者

strange error with maven dependency copy

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?


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

  • Chapter 8. Maven Assemblies
  • 8.5.4. dependencySets Section
  • 8.6. Best Practices

References

  • Maven Assembly Plugin
  • Descriptor Format


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜