2011-06-14 51 views
1

我正在构建一个Maven项目,该项目由不使用Maven的第三方提供的库构建。他们每两周提供一次新版本。作为构建过程的一部分,我如何自动将外部罐子部署到我的存储库?

我试图尽可能自动化工作,使代码在我们的项目中可用。其中一项任务是从目录中取出一组jar并将其作为工件上传到我们的存储库。

作为构建的一部分,可以做到这一步吗?理想情况下,我想最终得到一个类似的转换项目。

<?xml version="1.0" encoding="UTF-8"?> 
<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>com.convertor</groupId> 
    <artifactId>thirdpartyconvertor</artifactId> 
    <version>THIRD_PARTY_VERSION</version> 
    <packaging>jar</packaging> 

    <properties> 
     <jarLocation>${someKnownLocation}\${version}</caplinSdkVersion> 
    </properties> 

    <build> 
     <plugins> 
      <plugin> 
       <!-- 
        Mystery plugin that goes through the third party jar directory and deploys each jar file as 
        <groupId>com.thirdparty</groupId> 
        <artifactId>THE_JAR_NAME</artifactId> 
        <version>${version}</version> 
       --> 
     </plugins> 
    </build> 


    <dependencies> 
     <dependency> 
      <groupId>com.thirdparty</groupId> 
      <artifactId>all-jars</artifactId> 
      <version>${version}</version> 
     </dependency> 

    </dependencies> 
</project> 

任何想法?

回答

1

它闻起来有点,但我最终使用maven ant插件来运行maven ant任务来完成工作。

最终的结果是,特定目录中的所有jar文件都被部署到artifactory中,并且创建了一个依赖于所有添加的jar项目的进一步项目。

<plugin> 
       <artifactId>maven-antrun-plugin</artifactId> 
       <version>1.6</version> 
       <executions> 
        <execution> 
         <id>install</id> 
         <phase>install</phase> 
         <configuration> 
          <target> 
           <taskdef resource="net/sf/antcontrib/antlib.xml"> 
            <classpath> 
             <pathelement 
               location="${releaseDirectory}\thirdparty\common\antcontrib\1.0b3\ant-contrib-1.0b3.jar"/> 
            </classpath> 
           </taskdef> 

           <taskdef resource="org/apache/maven/artifact/ant/antlib.xml"> 
            <classpath> 
             <pathelement 
               location="${releaseDirectory}\thirdparty\common\maven-ant-tasks\2.1.1\maven-ant-tasks-2.1.1.jar"/> 
            </classpath> 
           </taskdef> 

           <!-- write a pom that depends on all the jars we find. --> 
           <var name="temp.pom.file" value="${build.directory}/maven/combined/pom.xml"/> 
           <echo message='&lt;?xml version="1.0" encoding="UTF-8"?&gt;${line.separator}' 
             file='${temp.pom.file}'/> 
           <echo message='&lt;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"&gt;${line.separator}' 
             file='${temp.pom.file}' append='true'/> 
           <echo message=' &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;${line.separator}' 
             file='${temp.pom.file}' append='true'/> 
           <echo message=' &lt;groupId&gt;com.mavenised&lt;/groupId&gt;${line.separator}' 
             file='${temp.pom.file}' append='true'/> 
           <echo message=' &lt;artifactId&gt;combined-java&lt;/artifactId&gt;${line.separator}' 
             file='${temp.pom.file}' append='true'/> 
           <echo message=' &lt;version&gt;${version}&lt;/version&gt;${line.separator}' 
             file='${temp.pom.file}' append='true'/> 
           <echo message=' &lt;packaging&gt;pom&lt;/packaging&gt;${line.separator}' 
             file='${temp.pom.file}' append='true'/> 
           <echo message=' &lt;dependencies&gt;${line.separator}' file='${temp.pom.file}' 
             append='true'/> 

           <for param="file"> 
            <path> 
             <fileset dir="${sdkDirectory}\lib\servlet"> 
              <include name="**/*.jar"/> 
             </fileset> 
            </path> 

            <sequential> 
             <propertyregex override="yes" 
                 property="jarName" 
                 input="@{file}" 
                 regexp="([^/\\]+)\.jar" 
                 select="\1"/> 

             <pom id="jarPom" groupId="com.mavenised" artifactId="${jarName}" 
              version="${version}" name="${jarName}"/> 

             <!-- the pom must be written to disk because of a bug in the ant plugin --> 
             <writepom pomRefId="jarPom" file="${build.directory}/maven/pom.xml"/> 
             <pom id="writtenPom" file="${build.directory}/maven/pom.xml"/> 

             <install file="@{file}"> 
              <pom refid="writtenPom"/> 
             </install> 

             <echo message=' &lt;dependency&gt;${line.separator}' file='${temp.pom.file}' append='true'/> 
             <echo message=' &lt;groupId&gt;com&lt;/groupId&gt;${line.separator}' file='${temp.pom.file}' append='true'/> 
             <echo message=' &lt;artifactId&gt;${jarName}&lt;/artifactId&gt;${line.separator}' file='${temp.pom.file}' append='true'/> 
             <echo message=' &lt;version&gt;${version}&lt;/version&gt;${line.separator}' file='${temp.pom.file}' append='true'/> 
             <echo message=' &lt;/dependency&gt;${line.separator}' file='${temp.pom.file}' append='true'/> 

            </sequential> 
           </for> 

           <echo message=' &lt;/dependencies&gt;${line.separator}' file='${temp.pom.file}' 
             append='true'/> 
           <echo message='&lt;/project&gt;${line.separator}' file='${temp.pom.file}' 
             append='true'/> 

           <pom id="combinedPom" file="${temp.pom.file}"/> 

           <install file="${temp.pom.file}"> 
            <pom refid="combinedPom"/> 
           </install> 
          </target> 
         </configuration> 
         <goals> 
          <goal>run</goal> 
         </goals> 
        </execution> 
0

编辑:我知道这个问题是关于如何做到这一点“自动”,但我没有意识到任何自动的方式来实现所需的结果,所以我给了一个稍微不太理想的手动实现替代方案相同的结果。

有几种方法可以做到这一点。以下两种可能的解决方案都是围绕在库中手动安装jar来完成的。我没有意识到有任何插件可以做你正在问的东西(但这并不存在 - 但是!) - 如果没有人能提出这样的插件,你总是可以自己编写这样一个插件! ;-)

1)第一种方法是每次手动将指定jar手动安装到本地存储库中,每次插入时都会增加每个jar的版本号。

mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging> 

然后,您可以将jar作为另一个依赖关系引用。不过,我认为你需要在每个发行版中不断更改你的pom版本。 (我记得看到一种方式总是引用最新版本,但我认为它是为Maven v1,我没有它在Maven 2中工作 - 我敢肯定有人会添加一个注释,指示如何引用最新版本,如果可能的话)

2)第二种方法将是有用的,如果你有一个本地开发团队不只是几个人 - 这将是一个存储库管理器(Apache Archiva只是一个例子,我我个人使用过 - 有很多!),并使用Repo Manager用户界面在存储库中安装每个jar。这种方法的好处是,团队只需要安装一次Jar的每个版本,而不是先前的方法,这需要团队的每个成员在本地存储库中安装每个版本的jar。

我不知道这是否有帮助!

+0

是的,更自动的东西是我正在寻找。 – 2011-06-16 04:19:12

0

你提到“自动”在你的问题,我会假设你有一些像詹金斯CI工具。如果您正在使用Jenkins,则可以使用XShell插件添加命令行作业。

https://wiki.jenkins-ci.org/display/JENKINS/XShell+Plugin

你可以编写一个批处理/脚本,从出版商下载库,然后上传神器到存储库。

您的批处理/脚本可以自动管理版本号等,Jenkins可以自动处理定期更新。一旦你这样做了,你的项目也可以由Jenkins用你的新XShell作为父项来构建。

或者,而不是写一个批处理/脚本文件,你可以使用Maven的部署插件:

http://maven.apache.org/plugins/maven-deploy-plugin/

要部署使用Maven部署插件的第三方库,你仍然需要执行命令行,所以使用Jenkins或某种预定的命令行工具将使您“自动”。

+0

我们已经有团队城市运行。一个批处理文件可能会把jar放入回购站。还有一些其他maveny任务需要在同一时间完成。 (根据jar中的类创建插件,提取一堆javascript并将其转换为maven javascript项目)。我已经结束了一个嵌套的maven项目,其中一个模块正在做maven项目转换的jar。 – 2011-06-16 04:21:51

相关问题