简体   繁体   中英

Using Maven to build and install seperate jar dependencies

Main Module
-pom.xml
Module1
jar dependency
Module2
jar dependency

I am new to Maven and am wondering what the best practice is for configuring the above setup. We are upgrading our version of Alfresco (currently all of the above are compile via ANT) and for testing purposes and to make headway on the project, I initially just compiled Module1 and Module2 using their existing ant build scripts and then did a manual install into the Maven repository. I manually added the dependency in my Main Model pom. Module1 and Module2 need to be compiled and rebuild every time we update Main Module. They are shared with other projects and can change frequently.

What I am working on at this point is the following: In Main Module pom.xml, I am using maven-antrun-plugin to run the associated ant build scripts for Module1 and Module2. This is working fine and produces the two jar. Now I would like to have my main module pom.xml file install the two jars into the maven repository. My dependencies in my pom.xml have an issue when I update the project version since the pom.xml has not been run yet to install the two jars.

    <dependency>
        <groupId>ca.gc.hc.nhpd</groupId>
        <artifactId>EformExtractor</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>ca.gc.hc.nhpd</groupId>
        <artifactId>SubmissionConsumer</artifactId>
        <version>${project.version}</version>
    </dependency>

Am I going about this incorrectly? It will work if I run the ant script and install manually and then add the correct version in the pom.xml dependency. We wish this to happen automatically though. We don't want to have to do this manually for every build we do.

Perhaps you should structure this project with parent and child pom.xml files:

MainModule
|-- pom.xml
|-- ModuleA
|   |--pom.xml
|-- ModuleB
    |--pom.xml

The parent pom.xml would look something like the one in this example .

The pom.xml for ModuleA and ModuleB could run their Ant scripts, if necessary. Then you should be able to run mvn install at the parent level to install ModuleA and ModuleB to your local Maven repository.

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