dimanche 23 octobre 2011

How to install GXT (or any other binary distribution) into Nexus (or any other maven repository)



I needed to upload a 3rd party jar to Nexus. This is pretty easy when you use the admin UI, but I couldn't find a way to upload the other artifacts (e.g. the sources and javadoc jars). Here's how to do it...



mvn deploy:deploy-file

The key is to use maven deploy plugin from the command line. It has a special goal 'deploy-file' that allows you to upload 3rd party binary jars.

Publishing JARs to maven

Since the maintainers of GXT don't really do maven (and the central maven repository hasn't been updated to version 1.2.3 yet), I decided to put the latest release of GXT into our own Nexus repository. After downloading the latest release, here's how I pushed it to our repository: First I uploaded the binary jar:
mvn deploy:deploy-file -DgroupId=com.extjs \
          -DartifactId=gxt \
          -Dpackaging=jar \
          -Dversion=1.2.3 \
          -Dfile=gxt.jar \
          -Durl=http://repo/nexus/content/repositories/releases \
          -DrepositoryId=IdInM2settings
Then I uploaded it again as the sources jar:
mvn deploy:deploy-file -DgroupId=com.extjs \
          -DartifactId=gxt \
          -Dpackaging=jar \
          -Dversion=1.2.3 \
          -Dfile=gxt.jar \ 
          -Durl=http://repo/nexus/content/repositories/releases \
          -DrepositoryId=IdInM2settings \
          -Dclassifier=sources
Note: I upload the sources jar so all of the IDE features work (helpful code sense, debugging, etc).

Upload permissions

You need to make sure that your ~/.m2/settings.xml file has the username and password that isallowed to add resources to your repository:
<settings>
   <servers>
        <server>
           <id>IdInM2settings</id>
           <username>admin</username>
           <password>password</password>
        </server>
    </servers>
    ...
</settings>

Notes

Here's the upload url that is created from the arguments passed to 'deploy-file':
${url}/${groupId}/${artifactId}/${artifact}-${version}-${classifier}.${packaging}
It replaces . with / in the ${groupId}.
It will create a pom.xml file for you if one has not already been created. The second upload will update the pom.

Aucun commentaire:

Enregistrer un commentaire