Have you ever tried to use Maven dependencies within Ivy projects? If so, you may know that this was possible, but a bit hacky 🙃...
Recently we finally addressed this issue, so now it works much more comfortably and with known Maven standards 🎉.
With 9.2:
Let's assume that we need an opencsv library in our project. Then we need to do the following:
- Make sure that you use the latest Project-Build-Plugin (9.2.1 at this moment)
- Make sure that your project is a maven nature project (Right click on project -> Configure -> Convert to Maven Project)
Now you can add some Maven dependecies using the IDE or you can add them directly to your project pom.xml
file:
<dependencies>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>4.1</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
As you can see above, I also exclude transient dependencies of the opencsv library. This is because all the dependencies this library needs (some Apache Commons libraries) are already provided by core 🚚. So I exclude these libraries here to reduce the size of the final ivy archive.
You should also make sure that you only include dependencies which are needed for the runtime. For example, do not include test dependecies like junit
or simply add <scope>test</scope>
to it.
Now when you export the project from the Designer or build it with the project-build-plugin
🔨, all maven dependecies should be added to the lib/mvn-deps
folder.
Before 9.2:
If you're working with a version before 9.2, you still need to go with the old way:
- Copy the libary with the
maven-dependecy-plugin
:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy.maven.dependencies</id>
<goals><goal>copy</goal></goals>
<phase>generate-resources</phase>
<configuration>
<outputDirectory>lib</outputDirectory>
<artifactItems>
<artifactItem>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>4.1</version>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
- Run
mvn clean generate-resources
- Refresh your project in the Designer workspace
- Add the Jar's in the
lib
directory to the project .classpath
(Java Perspective -> Right click on Jar -> build path -> add to build path)
Migrate to 9.2:
Theoretically no migration is necessary, because the old hack still works 😎, but there is a migration chapter in our Migration Notes 📕.