简体   繁体   English

是否可以构建同一模块的多个版本?

[英]Is it possible to build multiple versions of the same module?

I'm trying to design a solution that allows a single Virgo application to provide backwards compatibility for integrating with multiple versions of an external service provider. 我正在尝试设计一种解决方案,该解决方案允许单个Virgo应用程序提供向后兼容性以与多个版本的外部服务提供商集成。

For example, the application, call it PortalApp, is a portal that currently integrates with version 2.3 of ThirdPartyApp. 例如,名为PortalApp的应用程序是当前与ThirdPartyApp的2.3版集成的门户。 ThirdPartyApp v3.0 is coming out soon with new features, so the new version of PortalApp will have features that won't work with the older version of ThirdPartyApp. ThirdPartyApp v3.0即将推出,并具有新功能,因此新版本的PortalApp将具有旧版本的ThirdPartyApp无法使用的功能。

I don't require being able to serve both versions dynamically at run time, just one or the other. 我不需要能够在运行时动态地同时服务两个版本,而一个或另一个就可以。 I've already established that I can have two versions of a module in the Virgo usr repository, and load one or the other based on the .plan file used at server start. 我已经确定可以在Virgo usr存储库中拥有一个模块的两个版本,并根据服务器启动时使用的.plan文件加载一个或另一个版本。

For simplicity, we can assume project is currently set up like this: 为了简单起见,我们可以假设当前项目的设置如下:

PortalApp
- web-app
- ThirdPartyProvider

There are a number of other modules that depend on ThirdPartyProvider, so changing the ArtifactId would break those chains. 还有许多其他模块依赖ThirdPartyProvider,因此更改ArtifactId会破坏这些链。 What I'd like to do is build two different versions of the same module. 我想做的是构建同一模块的两个不同版本。 Something like this: 像这样:

PortalApp
- web-app
- - 1.0
- - 2.0
- ThirdPartyProvider
- - 1.0
- - 2.0

I tried creating a parent pom.xml in web-app (packaging: pom) that identified both 1.0 and 2.0 as modules, but only one of them builds. 我尝试在web-app(包装:pom)中创建一个父pom.xml,将1.0和2.0都标识为模块,但是只有其中一个可以构建。

Can a single build of the PortalApp project build both versions of a module? PortalApp项目的单个版本可以同时构建模块的两个版本吗?

No, it's not possible (actually it is, but you really wouldn't want to do that because it's a world of pain). 不,这是不可能的(实际上是,但是您真的不想这样做,因为这是一个痛苦的世界)。 The pom has a version tag and this is the version of the artifact that is built. pom具有一个version标记,这是所构建工件的版本。

Rather than do that, you should create a multi-module project, with one module for each web-app, as you have in your second diagram, each depending on the relevant version of the ThirdPartyProvider. 而不是这样做,您应该创建一个多模块项目,为每个Web应用程序提供一个模块,就像在第二张图中一样,每个模块都取决于ThirdPartyProvider的相关版本。 You would then factor out the common code from these web-apps - usually this produces two things, a common web-app which you depend on from web-app:1 and web-app:2 (this will create what's called an 'overlay' which pushes the contents of common into the other two apps, but which doesn't overwrite existing files), and a shared java library containing the common java classes (depending on how you use the third-party api you may need two of these too). 然后,您需要从这些Web应用程序中剔除通用代码-通常,这会产生两件事,即您依赖于Web-app:1和Web-app:2依赖的通用Web应用程序(这将创建所谓的“重叠式广告” '将common的内容推送到其他两个应用程序中,但不会覆盖现有文件),以及一个包含common java类的共享java库(取决于您使用第三方api的方式,您可能需要其中两个)太)。

You then build both web-apps, producing two artifacts, web-app-1.war and web-app-2.war, each with a dependency on the relevant ThridPartyProvider and on the common classes lib. 然后,您将构建两个Web应用程序,生成两个工件,即web-app-1.war和web-app-2.war,每个工件都依赖于相关的ThridPartyProvider和公共类lib。

In order to keep all artifacts in the same version you could use Versions Maven Plugin to set the version 2.0 or 3.0 and in your build you can use mvn package -DthirdParty.version=3.0 为了使所有工件保持同一版本,您可以使用Versions Maven插件来设置版本2.0或3.0,并且在您的构建中,您可以使用mvn包-DthirdParty.version = 3.0

Make sure your pom.xml looks like this 确保您的pom.xml看起来像这样

<properties>
    <thirdParty.version>2.0</thirdParty.version>
</properties>

So you can use Jenkins in order to automate buils and ensure that eveyrhing is ok in your Continuous Integration process. 因此,您可以使用Jenkins来自动执行构建,并确保在持续集成过程中可以进行eveyrhing。

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

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