14

We are using ANT for our build process and don't have plans to change this in the near future.

Is it possible to use Maven to just fetch common Open Source jar files (e.g. Log4J, SWT, JFace) and put them in the right location of our project, so we don't have to store them in our version control — preferable without creating the typical Maven-cache in the home directory?

jmj
  • 237,923
  • 42
  • 401
  • 438
Mot
  • 28,248
  • 23
  • 84
  • 121

4 Answers4

20

NO NO NO Everyone!

If you're using Ant, the best way to use Maven repositories to download jar dependencies is to use Ivy with Ant. That's exactly what Ivy is for.

Installing Ivy and getting to work with current Ant projects is simple to do. It works with Nexus and Artifactory if you use those as your local Maven repositories.

Take a look at Ivy. It is probably exactly what you want.

David W.
  • 105,218
  • 39
  • 216
  • 337
  • Or maven ant tasks. Either uses ant to download artifacts from a repository. http://maven.apache.org/ant-tasks/index.html – michael Dec 28 '12 at 15:30
  • Do not use maven-ant-tasks it's a very old project that should be deprecated, it does basic resolution but anything beyond that will likely come up short – niken Oct 18 '17 at 14:39
6

In variation of org.life.java's answer, I would not do mvn install.

Instead, in the pom.xml I would add the following bit:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Now you just need to do mvn generate-sources, which is a lot faster than the full mvn install, and all dependencies will be copied to the specified directory.


Oh btw, isn't that what Apache Ivy is about? Extending Ant to understand Maven's dependency management?

Community
  • 1
  • 1
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
  • I don't know about Apache Ivy either. Is it possible to copy certain libraries here and others there? – Mot Dec 31 '10 at 10:18
  • 1
    @mklhmnn I have never tried Ivy. I am a maven user who sometimes uses ant, not the other way around, so I wouldn't be the target audience for Ivy. But here's a quote from the features page: 'Apache Ivy can therefore be used to bring the dependency management feature of Apache Maven™ to Apache Ant build files, for those of you who already use Apache Ant and who do not want to setup an Apache Maven project. But Apache Ivy does not stop there, it provides many more great features!' http://ant.apache.org/ivy/features.html – Sean Patrick Floyd Dec 31 '10 at 11:38
4

It's possible, you should use maven-ant-tasks.

In particular its dependencies ant task. With this setup no Maven install is required.

<?xml version="1.0" encoding="UTF-8"?>
<project
  name="download-dependency"
  basedir="."
  default="download-dependency"
  xmlns:artifact="antlib:org.apache.maven.artifact.ant"
>
  <target name="download-dependency">

    ... define properties ...

    <taskdef
      resource="org/apache/maven/artifact/ant/antlib.xml"
      uri="antlib:org.apache.maven.artifact.ant"
    />

    <artifact:dependencies>
      <localRepository path="${local-repo.dir}"/>
      <remoteRepository id="central" url="${repository-uri}"/>
      <dependency
        groupId="${groupId}"
        artifactId="${artifactId}"
        version="${version}"
        type="${type}"
        classifier="${classifier}"
        scope="runtime"
      />
    </artifact:dependencies>
  </target>
</project>

The only binary you should check into your project is maven-ant-tasks.jar.

Actually in our project I used Sonatype Nexus ( documentation ) Maven repository manager to centralize access to different repositories and even maintain some binaries unique to our environment. With Nexus' help I just fetch maven-ant-tasks.jar with ant's <get> task from a known URL. You don't have to use Nexus, but it greatly speeds up builds, because it caches binaries close to your developer's machines.

Alexander Pogrebnyak
  • 44,836
  • 10
  • 105
  • 121
2

Ivy does just this, when it bootstraps itself:
http://ant.apache.org/ivy/history/latest-milestone/samples/build.xml

<property name="ivy.install.version" value="2.0.0-beta1"/>
<property name="ivy.jar.dir" value="lib"/>
<property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar"/>
<target name="resolve" unless="skip.download">
    <mkdir dir="${ivy.jar.dir}"/>
    <echo message="installing ivy..."/>
    <get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar" dest="${ivy.jar.file}" usetimestamp="true"/>
</target> 
user77115
  • 5,517
  • 6
  • 37
  • 40