Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any plugin that enables non-Maven dependencies loading/using?

Tags:

java

maven-2

I need to use a third-party JAR library in my project (actually it's Dresden OCL for Eclipse) that is not provided as a Maven artifact. Instead, it's just a downloadable JAR file. Can I instruct Maven to use this JAR file the same way I'm using <dependencies>? I suppose that there should be some plugin for this purpose?

ps. I just don't want to add 35Mb of third-party binaries into my SVN repository.

Would be nice to have it configured this way:

<build>
  <plugins>
    <plugin>
      <groupId>com.example</groupId>
      <artifactId>non-maven-dependencies-injector</artifactId>
      <configuration>
        <libraries>
          <library>http://www.example.com/something*.jar</library>
          <library>http://www.example.com/something-else*.jar</library>
        </libraries>
      </configuration>
    </plugin>
  <plugins>
</build>

And this plugin would 1) download these JAR files, and 2) add them as dependencies into pom.xml. Maybe this plugin could store them somewhere in ~/.m2/temp/...

like image 420
yegor256 Avatar asked Feb 05 '11 09:02

yegor256


People also ask

What is difference between Maven dependency and plugin?

A plugin is an extension to Maven, something used to produce your artifact (maven-jar-plugin for an example, is used to, you guess it, make a jar out of your compiled classes and resources). A dependency is a library that is needed by the application you are building, at compile and/or test and/or runtime time.

Which one among the following plugin type does Maven provides?

Maven has two types of plugins: Build – executed during the build process. Examples include Clean, Install, and Surefire plugins. These should be configured in the build section of the POM.


2 Answers

yes you can install it into your local repository with maven-install plugin

mvn install:install-file -Dfile=your-artifact-1.0.jar \
                         -DgroupId=org.some.group \
                         -DartifactId=your-artifact \
                         -Dversion=1.0 \
                         -Dpackaging=jar \
                         -DgeneratePom=true

If you want your other team members to be able to download this dependency without having to install it them thelves, you need to setup your own artifact repo, and deploy the artifact there with maven-deploy-plugin in same way as you installed it localy.

like image 154
lweller Avatar answered Sep 18 '22 17:09

lweller


Yes. This (using non-Mavenized dependencies) is supported by the maven-external-dependency-plugin.

Example:

<artifactItem>
    <groupId>jwbroek.cuelib</groupId>
    <artifactId>cuelib</artifactId>
    <version>${cuelib-version}</version>
    <packaging>jar</packaging>
    <downloadUrl>http://cuelib.googlecode.com/files/cuelib-${cuelib-version}.jar</downloadUrl>
    <checksum>d03b6b960b3b83a2a419e8b5f07b6ba4bd18387b</checksum>
</artifactItem>

It can also extract artifacts from zip files:

<artifactItem>
    <groupId>mediautil</groupId>
    <artifactId>mediautil</artifactId>
    <version>${mediautil-version}</version>
    <packaging>jar</packaging>
    <install>true</install>
    <force>false</force>
    <downloadUrl>http://downloads.sourceforge.net/project/mediachest/MediaUtil/Version%201.0/mediautil-1.zip</downloadUrl>
    <checksum>aa7ae51bb24a9268a8e57c6afe478c4293f84fda</checksum>
    <extractFile>mediautil-${mediautil-version}/mediautil-${mediautil-version}.jar</extractFile>
    <extractFileChecksum>e843cd55def75dce57123c79b7f36caca4841466</extractFileChecksum>
</artifactItem>
like image 38
chocolateboy Avatar answered Sep 18 '22 17:09

chocolateboy