2018-07-31

Quick and dirty mavenization of an existing project

This is my lazy way to get anything to a Maven repo. Shown on my mavenization of the Sardine library.

See also: How to add existing project's jar to SVN-based Maven repository


  1. Download the binaries of the lib you want to mavenize.
  2. Create a script to put everything to the maven repo.

    Choose a group name for the library and it's deps.

    You should not use the lib's package names, because it could interfere later

    with the official artifacts, should it ever be mavenized.

    I usually use my project's name with the lib's name appended – org.jboss.qa.ews.sardine in this case.

    @ECHO off
    ECHO echo Edit this file before use. Check the -DartifactId and -Dversion params.
    ECHO return
    
    ECHO cmd /C mvn install:install-file -DpomFile=sardine-pom.xml -Dpackaging=jar -DgeneratePom=true -DgroupId=org.jboss.qa.ews.sardine -Dfile=sardine-80\sardine.jar -DartifactId=sardine -Dversion=80
    
    FOR %%f IN ( sardine-80\lib\*.jar) DO ECHO cmd /C mvn install:install-file -Dpackaging=jar -DgeneratePom=true -DgroupId=org.jboss.qa.ews.sardine -Dfile=%%f -DartifactId=%%~nf -Dversion=%%~nf

    This will create something like this:

    echo Edit this file before use. Check the -DartifactId and -Dversion params.
    return
    
    cmd /C mvn install:install-file -DpomFile=sardine-pom.xml -Dpackaging=jar -DgeneratePom=true -DgroupId=org.jboss.qa.ews.sardine -Dfile=sardine-80\sardine.jar -DartifactId=sardine -Dversion=80
    
    cmd /C mvn install:install-file -Dpackaging=jar -DgeneratePom=true -DgroupId=org.jboss.qa.ews.sardine -Dfile=sardine-80\lib\ant-googlecode-0.0.2.jar -DartifactId=ant-googlecode -Dversion=0.0.2
    cmd /C mvn install:install-file -Dpackaging=jar -DgeneratePom=true -DgroupId=org.jboss.qa.ews.sardine -Dfile=sardine-80\lib\commons-logging-1.1.1.jar -DartifactId=commons-logging -Dversion=1.1.1
    cmd /C mvn install:install-file -Dpackaging=jar -DgeneratePom=true -DgroupId=org.jboss.qa.ews.sardine -Dfile=sardine-80\lib\httpclient-4.0.1.jar -DartifactId=httpclient -Dversion=4.0.1
    cmd /C mvn install:install-file -Dpackaging=jar -DgeneratePom=true -DgroupId=org.jboss.qa.ews.sardine -Dfile=sardine-80\lib\httpcore-4.0.1.jar -DartifactId=httpcore -Dversion=4.0.1
    cmd /C mvn install:install-file -Dpackaging=jar -DgeneratePom=true -DgroupId=org.jboss.qa.ews.sardine -Dfile=sardine-80\lib\junit-4.8.1.jar -DartifactId=junit -Dversion=4.8.1
    cmd /C mvn install:install-file -Dpackaging=jar -DgeneratePom=true -DgroupId=org.jboss.qa.ews.sardine -Dfile=sardine-80\lib\svnkit.jar -DartifactId=svnkit -Dversion=0.0
    cmd /C mvn install:install-file -Dpackaging=jar -DgeneratePom=true -DgroupId=org.jboss.qa.ews.sardine -Dfile=sardine-80\lib\svntask.jar -DartifactId=svntask -Dversion=0.0
  3. Create a pom.xml file, which will describe the mavenized library's depen­dencies.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.jboss.qa.ews.sardine</groupId>
  <artifactId>sardine</artifactId>
  <packaging>jar</packaging>
  <version>80</version>

  <name>Sardine mavenized</name>
  <url>http://www.jboss.org/</url>

  <dependencies>
  </dependencies>

</project>
  1. Most of the deps should be found in some existing Maven repository.

    Try to find as much as you can (the exact versions!), add them as a dependency to the pom.xml, and comment them out from the script.

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
      <version>1.1.1</version>
    </dependency>
    
    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpclient</artifactId>
      <version>4.0.1</version>
    </dependency>
    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpcore</artifactId>
      <version>4.0.1</version>
    </dependency>
    
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.8.1</version>
    </dependency>
    
    <dependency>
      <groupId>org.tmatesoft.svnkit</groupId>
      <artifactId>svnkit</artifactId>
      <version>1.3.2-1</version>
    </dependency>
    
    <dependency>
      <groupId>org.jboss.qa.ews.sardine</groupId>
      <artifactId>ant-googlecode</artifactId>
      <version>0.0.2</version>
    </dependency>
    
    
    <dependency>
      <groupId>org.jboss.qa.ews.sardine</groupId>
      <artifactId>svntask</artifactId>
      <version>0.0</version>
    </dependency>
    cmd /C mvn install:install-file -DpomFile=sardine-pom.xml -Dpackaging=jar -DgeneratePom=true -DgroupId=org.jboss.qa.ews.sardine -Dfile=sardine-80\sardine.jar -DartifactId=sardine -Dversion=80
    
    cmd /C mvn install:install-file -Dpackaging=jar -DgeneratePom=true -DgroupId=org.jboss.qa.ews.sardine -Dfile=sardine-80\lib\ant-googlecode-0.0.2.jar -DartifactId=ant-googlecode -Dversion=0.0.2
    @rem cmd /C mvn install:install-file -Dpackaging=jar -DgeneratePom=true -DgroupId=org.jboss.qa.ews.sardine -Dfile=sardine-80\lib\commons-logging-1.1.1.jar -DartifactId=commons-logging -Dversion=1.1.1
    @rem cmd /C mvn install:install-file -Dpackaging=jar -DgeneratePom=true -DgroupId=org.jboss.qa.ews.sardine -Dfile=sardine-80\lib\httpclient-4.0.1.jar -DartifactId=httpclient -Dversion=4.0.1
    @rem cmd /C mvn install:install-file -Dpackaging=jar -DgeneratePom=true -DgroupId=org.jboss.qa.ews.sardine -Dfile=sardine-80\lib\httpcore-4.0.1.jar -DartifactId=httpcore -Dversion=4.0.1
    @rem cmd /C mvn install:install-file -Dpackaging=jar -DgeneratePom=true -DgroupId=org.jboss.qa.ews.sardine -Dfile=sardine-80\lib\junit-4.8.1.jar -DartifactId=junit -Dversion=4.8.1
    cmd /C mvn install:install-file -Dpackaging=jar -DgeneratePom=true -DgroupId=org.jboss.qa.ews.sardine -Dfile=sardine-80\lib\svnkit.jar -DartifactId=svnkit -Dversion=0.0
    cmd /C mvn install:install-file -Dpackaging=jar -DgeneratePom=true -DgroupId=org.jboss.qa.ews.sardine -Dfile=sardine-80\lib\svntask.jar -DartifactId=svntask -Dversion=0.0
  1. Some of the libs probably only serve the build process, in this case, svnkit, svntask and ant-googlecode (I just guessed from the names).

    These are going to be removed too.

  2. As you see, only the library itself left for addition to a maven repo.

    So, perform this:

    mvn install:install-file -DpomFile=sardine-pom.xml -Dpackaging=jar -DgeneratePom=true -DgroupId=org.jboss.qa.ews.sardine -Dfile=sardine-80\sardine.jar -DartifactId=sardine -Dversion=80
  1. Go to your local maven repo and find the installed library there (t:\data\.m2\repository\org\jboss\qa\ews\sardine\sardine in my case).

    Copy it to some publicly accessible site, where it can be downloaded from using plain HTTP.

    I used Google Code SVN. svn --non-recursive might help you with this task.

Done.


0