Maven publish & consume the third-party runtime jars while building our own custom.jar

huangapple go评论78阅读模式
英文:

Maven publish & consume the third-party runtime jars while building our own custom.jar

问题

我有一个Maven项目,我们正在使用S3存储库加载内部的abc-1.0.jar,以及abc-1.0.jar所需的任何运行时依赖项,我们以.zip的形式加载,并将其解压缩,如下所示:

有趣的注: 当我说第三方运行时jar包是一个zip时,有些jar包可能在构建abc-1.0.jar时没有被使用过。

project.zip
 -- lib
    -- abc-1.0.jar
    -- runtime_jars_for_abc.jar
    -- runtime_jars_for_project.jar

有可能当将abc-1.0.jar交付到my-project时,运行时zip可能会有一组jar,但对于abc-2.0.jar,我需要提供另一组jar

我通过以zip的形式进行交付并在创建project.zip时进行解压缩来解决了这个问题。

但是,是否有可能我可以将这些runtime.jar与我的abc-1.0.jarabc-2.0.jar一起发布或公告,以便my-project/pom.xml可以在运行时从mavenCentral()或我的内部maven-repo中动态地获取这些公告?

编辑

我在这里找到了maven changes插件 https://maven.apache.org/plugins/maven-changes-plugin/。这在很大程度上将发布新的变更,但我如何在每次新构建时动态地消耗这些新变更呢? 有什么想法吗? 🤔

*我想的是将abc-1.0.jar与其abc-1.0-pom.xml文件一起推送,该文件应该包含一些自定义范围或依赖jar的逻辑分组,以便我可以在消费项目中指定那些自定义范围分组,并使用maven copy dependencies插件 https://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-project-dependencies.html 来独特地复制那些jar,但不幸的是,Maven不支持自定义范围 😞

英文:

I've a maven project for which we are loading internal abc-1.0.jar using S3 repository and whatever runtime dependencies requires for abc-1.0.jar to be a part of my project, we load in the form of .zip and extract it as

Interesting Note: When I say third-party runtime jars as a zip, there are some jars which might not have used while building abc-1.0.jar

project.zip
 -- lib
    -- abc-1.0.jar
    -- runtime_jars_for_abc.jar
    -- runtime_jars_for_project.jar

There is possibility that when deliver abc-1.0.jar jar to my-project the runtime zip might have one set of jars but for abc-2.0.jar I need to ship another set of jars.

I've solved the problem by shipping it in the form of zip and extracting it while creating the project.zip

But, is it possible that I can ship or announce those runtime.jar along with my abc-1.0.jar or abc-2.0.jar so that my-project/pom.xml can consume that announcement on the fly from either mavenCentral() or my internal maven-repo?

EDIT

I found maven changes plugin here https://maven.apache.org/plugins/maven-changes-plugin/. this is mostly going to publish the new changes but how can I dynamically consume the new changes for each new build? any thoughts? 🤔

*What I was thinking is to push the abc-1.0.jar along with it's abc-1.0-pom.xml file which should consist of some custom scope or logical grouping of dependent jar, so that I can specify those custom scopes or groups in consumption project to uniquely copy those jars using maven copy dependencies plugin https://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-project-dependencies.html but unfortunately maven doesn't support custom scopes 😞

答案1

得分: 1

在你的项目b中,在版本前面加上 -SNAPSHOT,就像这样:

<groupId>my.groupid</groupId>
<artifactId>my.artifactid</artifactId>
<version>0.0.1-SNAPSHOT</version>

因此,每当你在项目b中进行更新时,你的项目a将从Maven仓库中选择最新的快照版本。

正如你所看到的,Maven通过添加时间戳来组织快照,以便提供最新的发布。

请注意,你的项目a绝不能将快照依赖项用于验收、预生产或生产环境!

英文:

In your project-b, prefix your version by -SNAPSHOT, like this

&lt;groupId&gt;my.groupid&lt;/groupId&gt;
&lt;artifactId&gt;my.artifactid&lt;/artifactId&gt;
&lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;

So, every time when you do update in your project-b, your project-a will pick the latest snapshot from maven repository

As you can see, maven organize snapshot by adding a timestamp to deliver the latest publish

Maven publish & consume the third-party runtime jars while building our own custom.jar

Note that your project-a must never go to acceptance, pprod or production environment with snapshot dependencies !

huangapple
  • 本文由 发表于 2020年9月19日 15:09:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/63966224.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定