开发者

I want to deploy a jar AND it's dependencies to a remote repository

开发者 https://www.devze.com 2023-01-16 07:28 出处:网络
Basically, I have a project and a Continuous Integration solution which I have no admin access to, that can\'t reach out of our network. Consequently, I want to deploy all of the jars for the project

Basically, I have a project and a Continuous Integration solution which I have no admin access to, that can't reach out of our network. Consequently, I want to deploy all of the jars for the project to our central maven repository which the CI solution can reach. They are in my local repo but it's a pretty complicated project. Can't I just set a flag or something and deploy both a jar and what ever else I have in the local repo that the jar depends on?

OK, I've had an 开发者_Go百科idea of my own since I first wrote this. What about this:

  1. Move my local maven repo off to a new name.
  2. Perform a build with -U flag so that a new repo is created with only the things I need for this project.
  3. Perform a merge from the newly created local repo to the remote repo.


What dborba said. I'd write a (bash/ruby) script to run the Maven Dependency Plugin, and then run deploy-file with the GAE attributes as reported by the Dependency Plugin. Assuming I had more than a few dependencies. Some repository managers (e.g. Nexus) are good at working out the GAE info.


Here is how I wound up handling this:

First I copied my local maven repo off to a new name. Then I ran "mvn -U clean install" ensuring that the resulting local maven repo contained only the jars needed for this specific build. Next I created this script (explained in detail for Windows users):

#!/bin/bash

for I in `find ~/.m2 -name "*.jar"`
do
        J=`echo $I | sed 's/jar$/pom/'`
        mvn deploy:deploy-file -DpomFile=$J -Dfile=$I -Durl=dav:http://maven.our.repo/maven2 -DrepositoryId=sharedRep
done

For those who don't read BASH, it grabs the full path and file names of all jar files in the .m2 subdirectory of the users home directory. This is usually where the user's local repo is located. Then it copies that and changes the file extension from "jar" to "pom" on the copy. Then we execute the maven command below:

mvn deploy:deploy-file -DpomFile=[pom file name here] -Dfile=[jar file name here] -Durl=dav:http://maven.our.repo/maven2 -DrepositoryId=sharedRep

This seems to work OK for getting the libraries in my local repo to the shared repo.


Check out Maven Deploy Plugin description and usage. I think the deploy-file mojo, although intended to deploy artifacts not built by maven, might help you do what you want.


In a blog post I described a similar scenario: Deploying a folder hierarchy to a Maven Repository. It uses GMaven (Groovy embedded in maven). If you take the code from that example, skip the directory walking and walk the project dependencies instead, you should almost be there.


Use maven-assembly-plugin to build a jar-with-dependencies, which will build a single executable jar with no external dependencies. See e.g.

How can I create an executable JAR with dependencies using Maven?

0

精彩评论

暂无评论...
验证码 换一张
取 消