2009-06-18 47 views

回答

0

你的意思是一種無需添加依賴於的pom.xml

因爲通過向您的pom.xml添加依賴項,Maven依賴項管理會自動從您指定的存儲庫檢索工件並將其安裝到本地存儲庫。

<dependencies> 
    <dependency> 
    <groupId>foo</groupId> 
    <artifactId>foo</artifactId> 
    <version>1.0.1</version> 
    </dependency> 
</dependencies> 
2

我不知道是否有一個Maven插件來處理這個問題,但它是相當簡單的使用Maven Ant tasks用於此目的。你並不需要有Maven的或POM文件,只需Ant和這個構建文件:

<?xml version="1.0" encoding="UTF-8"?> 
<project name="mvn-get" default="get" basedir="."> 
    <property name="maven.ant.tasks.jar" value="${ant.home}/lib/maven-ant-tasks-2.011.jar" /> 
    <property name="maven.ant.tasks.bootstrap.location" value="http://apache.inetbridge.net/maven/binaries/maven-ant-tasks-2.0.11.jar" /> 
    <available property="maven.ant.tasks.jar.exists" file="${maven.ant.tasks.jar}" /> 

    <!-- This will download the "latest version" of the maven-ant-tasks if needed --> 
    <target name="bootstrap_maven" unless="maven.ant.tasks.jar.exists"> 
     <get src="${maven.ant.tasks.bootstrap.location}" dest="${maven.ant.tasks.jar}" /> 
    </target> 

    <!-- This will initialize all the maven ant tasks and download the requested artifact and its dependencies --> 
    <target name="get" depends="bootstrap_maven" xmlns:artifact="urn:maven-artifact-ant"> 
     <path id="maven.ant.tasks.classpath" path="${maven.ant.tasks.jar}" /> 
     <typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="urn:maven-artifact-ant" classpathref="maven.ant.tasks.classpath" /> 
     <condition property="maven.repo.local" value="${maven.repo.local}" else="${user.home}/.m2/repository"> 
      <isset property="maven.repo.local" /> 
     </condition> 
     <echo>maven.repo.local=${maven.repo.local}</echo> 
     <artifact:localRepository id="local.repository" path="${maven.repo.local}" /> 
     <artifact:dependencies pathId="build.classpath" sourcesFilesetId="sources.id"> 
      <dependency groupId="${mvn.get.groupId}" artifactId="${mvn.get.artifactId}" version="${mvn.get.version}"/> 
      <localRepository refid="local.repository" /> 
     </artifact:dependencies> 
    </target> 

</project> 

使用如下命令行會做你想要什麼:

ant -Dmvn.get.groupId=commons-httpclient -Dmvn.get.artifactId=commons-httpclient -Dmvn.get.version=3.1 -Dmaven.repo.local=. 

的靈感這個來自這個excellent blog post.

+0

多數民衆贊成在一個好主意,但我正在尋找這是tuler回答。 – Mauli 2009-06-18 17:56:57

0

我用下面的shell腳本安裝一個共享的記錄替代,但在這種情況下,我已經有罐子手:

 
#! /bin/sh 

mvn install:install-file \ 
    -DgroupId=commons-logging \ 
    -DartifactId=commons-logging \ 
    -Dversion=99.0-does-not-exist \ 
    -Dpackaging=jar \ 
    -DcreateChecksum=true \ 
    -DpomFile=commons-logging-99.0-does-not-exist.pom \ 
    -Dfile=commons-logging-99.0-does-not-exist.jar 

mvn install:install-file \ 
    -DgroupId=commons-logging \ 
    -DartifactId=commons-logging-api \ 
    -Dversion=99.0-does-not-exist \ 
    -Dpackaging=jar \ 
    -DcreateChecksum=true \ 
    -DpomFile=commons-logging-api-99.0-does-not-exist.pom \ 
    -Dfile=commons-logging-api-99.0-does-not-exist.jar 

當你說「本地存儲庫」時,你的意思是你自己,作爲一個人,也就是說,在Unix上是〜/ .m2中的一個,還是你的公司存儲庫?這是一個不同的問題。對於前者,我有抖動;只需添加條目到你的pom。對於後者,請檢查存儲庫服務器的文檔以獲取如何獲取中央副本。

相關問題