从 ant 迁移到 Maven,生成 100 多个 jar [英] Migration from ant to Maven producing 100+ jars

查看:30
本文介绍了从 ant 迁移到 Maven,生成 100 多个 jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试将我们的构建从 ant 迁移到 maven.我工作的项目自古以来就在使用 ant.脚本非常复杂,其中构建工件是一个具有明确目录结构的 zip 文件.Build 创建了大约 108 个独特的 jar 并将它们与许多配置文件和其他 3rd 方 jar 一起打包到这个 zip 文件中.

We are trying to migrate our builds from ant to maven. Project I am working for is using ant since ages. Scripts are real complex where build artifact is a zip file having a definite directory structure. Build creates about 108 unique jars and packages them to this zip file along with many config files and other 3rd party jars.

即使在迁移到 Maven 之后,我们也需要此 zip 文件与现在相同.到目前为止,我只是 Maven 的学习者.我对你们的问题是,如果有一种方法可以使用一个 pom.xml 来生成多个 jar 文件,提供 jar 和包含列表,为每个排除包.

We need this zip file to be same as now even after migration to Maven. I am just a learner on Maven as of now. My question to you guys is that if there is a way using which I can use one pom.xml to produce more that one jar file, providing list of jars and includes, excludes packages for each.

我用谷歌搜索发现,如果我们需要来自一个项目的多个 jar 但不同的包,我们可以通过在每个包中放置一个 pom.xml(将从该包创建 jar)并使用依赖管理绑定所有来实现.

I googled and found that in case we need multiple jars from one project but different packages, we can do so by placing one pom.xml at each package (jar will be created from this package) and bonding all using dependency management.

但这并不能解决我的问题,因为拥有 100 多个 pom.xmls 似乎不是一个好主意.

But this does not solves my problem, as having 100+ pom.xmls does not seems to be a good idea.

希望我已经把我的问题说清楚了.请建议是否有出路.

Hope I have made my question clear. Please suggest if there is a way out.

推荐答案

在 Udo 的回答中添加另一个 Sonatype 博客帖子 附有说明从单个 Maven 项目生成多个 jar 的 Maven 反模式的图表.

Adding to Udo's answer here's another Sonatype blog posting with a diagram explaining the Maven anti-pattern of generating multiple jars from a single Maven project.

这两篇文章都建议在您的代码中采用模块化结构,而不是反对 Maven 将大型项目解耦为一组相互关联的子模块的方法.

Both articles recommend adopting a modular structure to your code rather than fighting Maven's approach of decoupling large projects into a set of interrelated sub-modules.

从查看您实际计划分享的文物开始.您的邮件表明您实际发布的唯一文件是一个包含 100 多个 jar 和其他文件的大型 zip 文件?

Start with looking at the arifacts you actually plan to share. Your mail suggests that the only file you're actually publishing is a large zip file containing 100+ jars and other files?

您可以调用 Maven 命令行工具 将此 zip 发布到 Maven 存储库:

You could invoke the Maven command-line tool to publish this zip to the Maven repository:

mvn deploy:deploy-file \
    -Durl=$REPO_URL \
    -DrepositoryId=$REPO_ID \
    -DgroupId=org.myorg \
    -DartifactId=myproj \
    -Dversion=1.2.3  \
    -Dpackaging=zip \
    -Dfile=myproj.zip

此方法也可用于发布 jar 和 POM(包含依赖项).最终,您将被需要维护的 POM 数量所淹没....届时,将该 jar 的构建重组为子模块会更简单.

This approach can also be used to publish jars and POMs (containing dependencies). Eventually you'll be overwhelmed with the number of POMs to maintain.... AT which time it would be simpler to restructure the building of that jar into a sub-module.

摆脱旧的 ANT 构建非常困难.这些通常包含复杂的、自定义的和难以重现的构建逻辑.对于此类项目,我建议使用 Apache ivy 来外部化 3rd 方依赖项并与其他项目(谁可能正在使用 Maven).

It's very difficult to walk away from a legacy ANT build. These often contain complex, custom and difficult to reproduce build logic. For such projects I recommend using Apache ivy to externalise 3rd party dependencies and share artifacts with other projects (who might be using Maven).

为此,我编写了一个 ant2ivy 脚本,用于生成初始常春藤设置,基于 jars已经存在于 ANT 项目的目录中(通常与源代码一起提交).

To that end I wrote an ant2ivy script for generating an initial ivy setup, based on the jars that already exist in the ANT project's directory (normally committed alongside the source).

使用 ivy 并不能让您远离创建项目子模块是个好主意的事实.但是,它确实使您能够对 ANT 构建进行现代化改造.

Using ivy doesn't get you away from the fact that it's a good idea to create project sub-modules. However it does enable you to modernise your ANT build.

是的,有 Maven ANT 任务可用.我不使用它们,因为它们基于 Maven 2.我很失望我们仍在等待他们的 Maven 3 替换 aether-ant-tasks(仅可从 GitHub 获得).Ivy 仍然是将非 Maven 客户端与 Maven 存储库集成的首选

Yes, there are Maven ANT tasks available. I don't use them because they based on Maven 2. I'm disappointed that we're still waiting for their Maven 3 replacement aether-ant-tasks (Only available from GitHub). Ivy is still the no1 choice for integrating non-Maven clients with a Maven repository

这篇关于从 ant 迁移到 Maven,生成 100 多个 jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆