简体   繁体   中英

Integrating 3rd party libraries with Maven build

Our Android app is currently being built using Maven. We also have our own in-house Maven server that stores internal artifacts that our final app is built from.

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).

Both libraries are available in .jar form, how can i (or should i) include these into our build process?

I thought of 2 options:

  1. Include the .jar directly in our VCS.
  2. Publish the .jars to our internal maven server, and use them as dependencies.

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)

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? 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.

First of all, its nice to have considered storing the .jar file in your VCS but I would dismiss it entirely. 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. 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. 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). Fear not however as the 'working' method does the trick just fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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