Integrating Maven & Non-maven projects

前端 未结 4 2075
独厮守ぢ
独厮守ぢ 2020-12-29 13:50

I\'m currently working on two projects simultaneously:

  • My main project (built with maven)
  • A spike of an open source project, which my main project d
相关标签:
4条回答
  • 2020-12-29 14:19

    If OSS project has dependencies - create a POM with those dependencies (your project will use them as transitive dependencies) and install that artifact and pom in local repository. If OSS project hasn't any other dependencies is even simpler - the POM is generated automatically during installing.

    For both cases use maven-install-plugin.

    mvn install:install-file -Dfile=your-artifact-1.0.jar \
                         [-DpomFile=your-pom.xml] \
                         [-Dsources=src.jar] \
                         [-Djavadoc=apidocs.jar] \
                         [-DgroupId=org.some.group] \
                         [-DartifactId=your-artifact] \
                         [-Dversion=1.0] \
                         [-Dpackaging=jar] \
                         [-Dclassifier=sources] \
                         [-DgeneratePom=true] \
                         [-DcreateChecksum=true]
    
    0 讨论(0)
  • 2020-12-29 14:21

    I think you probably need to bite the bullet and set up a POM for your OSS project tree. This is the painful part (as you would need to hunt down the details of specifying resources paths for various plugins involved depending on the OSS app type (i.e. web, etc.)). Good news is that this is a one time effort.

    Once that is done, your main project can refer to the (wrapped) OSS project as a dependency. Here a (standard maven) multi-project structure would apply.

    0 讨论(0)
  • 2020-12-29 14:25

    The solution I've used is the maven-ant tasks (http://maven.apache.org/ant-tasks/).

    I added an install task onto the build.xml file, which installs the compiled .jar into the local repo.

    While adding a full-fledged pom to the project would defintely be the best approach, this is a major chunk of work, and inflicts maven on the project (where the other users would prefer not to use it).

    0 讨论(0)
  • 2020-12-29 14:39

    I can think of several solutions:

    1. Mavenize the existing OSS project. This is of course the "ideal" option but often not feasible (even if you introduce the new build system in parallel of the existing one). The project has likely an existing project structure that differs from Maven's standard layout. Changing the existing layout and build script may not be desired by developers, adapting a Maven build to use a non standard layout can be painful. In both case, you're screwed.

    2. Wrap the existing Ant build with Maven. This can be nice if you want to include the build of the OSS project in the lifecycle of your project and have both of them built in one step. You can check this answer on SO for details on how to do this.

    3. Use Apache Ivy or Maven Ant Task in the existing build to produce and install a Maven artifact in your local repository. Use this artifact as a regular dependency in your Maven project (except that you'll have to declare its transitive dependencies manually). This is maybe the quicker and less intrusive approach if building both project separately is not a problem.

    It looks like you choose option 3. I think it's a good choice for a quick win.

    0 讨论(0)
提交回复
热议问题