Sebastian
Sebastian

Reputation: 1835

Instruct Maven to use Ivy's generated classpath

We are adding new code to an existing project that uses a custom build system developed with Ant and Ivy for dependency management.

Our new team is used to Maven and its features like testing execution, cobertura reports, etc.

Our question is: is it viable to add a pom.xml matching the current project structure, but instruct Maven to load its classpath from the "lib" dir already filled by Ivy? In other words: we want to use Maven without its dependency management.

One really dirty approach would be to generate one big jar from the libdir and config the pom.xml to include just that... but we believe there should be cleaner approach.

Any idea or recommendation?

Note: we are not interested in generating a pom.xml with dependencies from the Ivy config, we just want Maven to rely on Ivy's generated classpath. No need to discriminate between test/runtime/compile classpath.

Upvotes: 1

Views: 306

Answers (3)

Sebastian
Sebastian

Reputation: 1835

This is our final setup to solve this:

  • For each Ivy legacy project, use ivy:makepom and manual inspection to figure out the dependencies that we need to send to the new projects (Maven-based). This is a one-time process for each project.
  • Modify the legacy build system in a way that, every time a project is built, the identified dependencies are also exported to a mvn repo. Because de build machine holds the internal repo, we just use mvn install.
  • In the new maven projects, declare each dependency in the pom.xml and make sure the build system runs maven builds after the legacy builds.

Thank you all for your help!

Upvotes: 1

oers
oers

Reputation: 18714

Maybe the makepom task will be helpful, it creates a pom from the ivy file.

Example from that page:

<ivy:makepom ivyfile="${basedir}/path/to/ivy.xml" pomfile="${basedir}/path/to/module.pom" conf="default,runtime">
   <mapping conf="default" scope="compile"/>
   <mapping conf="runtime" scope="runtime"/>
   <dependency group="com.acme" artifact="acme-logging" version="1.0" optional="true"/>
</ivy:makepom>

Upvotes: 0

Raghuram
Raghuram

Reputation: 52665

One possibility is to use the system scope to define your dependencies in maven. This allows maven to use the jars downloaded by ivy for its dependencies.

e.g.

<dependencies>
    <dependency>
      <groupId>group.id</groupId>
      <artifactId>artifact</artifactId>
      <version>a.b.c</version>
      <scope>system</scope>
      <systemPath>${basedir}/lib/artifact-a.b.c.jar</systemPath>
    </dependency>
    ...
  </dependencies>

Upvotes: 0

Related Questions