简体   繁体   English

使用Maven构建和安装单独的jar依赖项

[英]Using Maven to build and install seperate jar dependencies

Main Module 主模块
-pom.xml -pom.xml
Module1 模块1
jar dependency jar依赖
Module2 模块2
jar dependency jar依赖

I am new to Maven and am wondering what the best practice is for configuring the above setup. 我是Maven的新手,我想知道配置上述设置的最佳实践是什么。 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. 我们正在升级Alfresco的版本(当前所有上述内容均通过ANT进行编译),并且出于测试目的并为了在项目上取得进展,我最初只是使用其现有的ant构建脚本来编译Module1和Module2,然后进行了手动安装Maven存储库。 I manually added the dependency in my Main Model pom. 我在主模型pom中手动添加了依赖项。 Module1 and Module2 need to be compiled and rebuild every time we update Main Module. 每次我们更新主模块时,都需要编译并重建Module1和Module2。 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. 此时,我正在处理以下内容:在主模块pom.xml中,我正在使用maven-antrun-plugin为Module1和Module2运行关联的ant构建脚本。 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. 现在,我想让我的主模块pom.xml文件将两个罐子安装到maven存储库中。 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. 更新项目版本时,由于尚未运行pom.xml来安装两个jar,因此我对pom.xml的依赖项出现问题。

    <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. 如果我运行ant脚本并手动安装,然后在pom.xml依赖项中添加正确的版本,则它将起作用。 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: 也许您应该使用父子pom.xml文件来构造该项目:

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

The parent pom.xml would look something like the one in this example . pom.xml看起来与本示例中的相似。

The pom.xml for ModuleA and ModuleB could run their Ant scripts, if necessary. 如有必要,用于ModuleAModuleBpom.xml可以运行其Ant脚本。 Then you should be able to run mvn install at the parent level to install ModuleA and ModuleB to your local Maven repository. 然后,您应该能够在父级别上运行mvn install ,以将ModuleAModuleB安装到本地Maven存储库。

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

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