简体   繁体   English

将第三方库与Maven构建集成

[英]Integrating 3rd party libraries with Maven build

Our Android app is currently being built using Maven. 我们目前正在使用Maven构建我们的Android应用。 We also have our own in-house Maven server that stores internal artifacts that our final app is built from. 我们还拥有自己的内部Maven服务器,用于存储最终应用程序所基于的内部构件。

We'd like to integrate a few external (3rd party) libraries to be used, however these libraries are not exported to any maven repository (MoPub and Chartboost). 我们想集成一些要使用的外部(第三方)库,但是这些库不会导出到任何Maven存储库(MoPub和Chartboost)。

Both libraries are available in .jar form, how can i (or should i) include these into our build process? 这两个库都以.jar形式提供,我如何(或应该)将它们包括在我们的构建过程中?

I thought of 2 options: 我想到了2个选择:

  1. Include the .jar directly in our VCS. 将.jar直接包含在我们的VCS中。
  2. Publish the .jars to our internal maven server, and use them as dependencies. 将.jars发布到我们的内部Maven服务器,并将其用作依赖项。

I am not a Maven expert and i don't know if #1 is even possible, or which of these options is better (and why) 我不是Maven专家,我也不知道#1甚至是可能的,或者这些选项哪个更好(为什么)

It think your best option is to contact the developers of the third party software and ask if they have a maven repo you can use? 它认为您最好的选择是与第三方软件的开发人员联系,并询问他们是否可以使用Maven存储库? If not you can ask them to create one. 如果没有,您可以要求他们创建一个。 Otherwise you could host them on your own repo, this is preferred to putting them in VCS as this should be reserved for source code, not compiled resources. 否则,您可以将它们托管在自己的存储库中,这比将它们放入VCS更可取,因为这应该保留给源代码,而不是编译资源。

First of all, its nice to have considered storing the .jar file in your VCS but I would dismiss it entirely. 首先,考虑将.jar文件存储在您的VCS中很好,但是我会完全将其关闭。 For 3rd party code it is best to include it in a build system but have it execute as a separate build, say the '3rd party' build or something like that. 对于第三方代码,最好将其包含在构建系统中,但应将其作为单独的构建执行,例如“第三方”构建或类似的东西。 The build itself should compile the Java code and then publish it to the internal maven server. 构建本身应该编译Java代码,然后将其发布到内部Maven服务器。 If the 3rd party code doesn't use Maven or Gradle or anything like that (or if it perhaps is not even written in java) then you can use the ant 'ant-maven-tasks' library to publish it. 如果第三方代码不使用Maven或Gradle或类似的东西(或者它甚至可能不是用Java编写的),那么您可以使用ant'ant-maven-tasks'库进行发布。 Below is an example: 下面是一个示例:

<path id="maven-ant-tasks.classpath" path="lib/maven-ant-tasks-2.1.3.jar" />

<typedef resource="org/apache/maven/artifact/ant/antlib.xml"
       uri="antlib:org.apache.maven.artifact.ant"
       classpathref="maven-ant-tasks.classpath" />

<target name="-after-build">
    <echo message="Building web jar..."/>
    <property name="output.jar.file" value="${buildbase.dir}/${app.name}-web.jar"/>
    <jar destfile="${output.jar.file}"
         basedir="${buildwebapp.dir}"
     />
     <!-- Look at using this when 'http://jira.codehaus.org/browse/MANTTASKS-170' is fixed 
          Alternatively, use the write around in this link if dynamic versioning is needed -->
     <!-- 
    <artifact:pom id="QuizEditorPOM" groupId="com.quiztailor" artifactId="QuizEditor"
                  version="1.0-SNAPSHOT" packaging="jar">
    </artifact:pom>
    -->

    <artifact:pom id="QuizEditorPOM" file="pom.xml" />

    <artifact:install file="${output.jar.file}" pomRefid="QuizEditorPOM"/>
</target>

Take heed of the comment there also as there is an alternative (IMHO) better method, still using maven ant tasks but there currently exists a bug with this method (jira ticket MANTTASKS-170). 也请留意该评论,因为还有一种替代(IMHO)更好的方法,仍使用行家ant任务,但是此方法目前存在一个错误(jira票MANTTASKS-170)。 Fear not however as the 'working' method does the trick just fine. 但是不要害怕,因为“有效”的方法可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM