Sunday, August 30, 2015

IBM never heard of maven and maven repo and what to do about this

There are a lot of reasons and most of them have to do with legal, but IBM developers can not use any Java jar they see fit but the ones that are approved by the legal.
For the same reason, I hope, they have their internal implementations of the fairly common jars.
One of those is JSON4J
IBM one got the base package com.ibm.json.* and almost same classes and methods but not quite same.

And this jar is not on the maven central but is part of almost any IBM distribution so it easy to get.

The problem is what to do when you try to use maven in a project that has this dependency and you want it all work nicely without hassle for the one who checks out the code?

I found a nice solution:
see the base here http://stackoverflow.com/questions/2229757/maven-add-a-dependency-to-a-jar-by-relative-path

so specifically for the JSON4J

Base assumption
Maven 3.3.3 in the $path
./ this is the root of the project we try to mavenize
Put the JSON4j.jar  in the ./lib <--- Do not check this in
Create a folder /project-repo <-- This will be checked in.

-------------------------------------------------------------------------------
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=.\lib\json4j.jar -DgroupId=com.ibm.json -DartifactId=json4j -Dversion=2.3 -Dpackaging=jar -DlocalRepositoryPath=./project-repo
-------------------------------------------------------------------------------
Then in the project POM:

This is your local repository for the project
-------------------------------------------------------------------------------
<repository>
<id>local-project-repo</id>
<url>file://${basedir}/project-repo</url> 
</repository>
-------------------------------------------------------------------------------
and this is the jar dependency 
-------------------------------------------------------------------------------
<dependency> 
<groupId>com.ibm.json</groupId> 
<artifactId>json4j</artifactId> 
<version>2.3</version> 
</dependency>
-------------------------------------------------------------------------------

And why IBM does not publish stuff to the maven central I do not know.




Followers