使用 IVY 将 SNAPSHOT 工件发布到 Maven - 有什么魔力?
我们遇到了一个稍微复杂的情况......
在大多数情况下,我们一直在使用 IVY 和 ANT 来管理我们的构建和依赖项。现在该公司正在转向使用 Maven。我们有一组称为公共库的项目,多个核心产品都使用它们。
常见库使用 IVY 并发布到 IVY 存储库。我们还需要为新的 Maven 项目提供通用库。因此,当构建并发布公共库时,我修改了脚本以发布到 Maven (Artifactory) 以及 IVY。以下是发布构建的 IVY 项目时调用的两个目标:
<target name="publish-ivyrepo" depends="load-ivysettings">
<ivy:resolve file="ivy.xml" />
<ivy:publish
module="${ant.project.name}"
artifactspattern="${dist.dir}/[artifact].[ext]"
resolver="integration"
pubrevision="${build.version}"
status="integration"
overwrite="true"
update="true"/>
</target>
<target name="publish-artifactory" depends="load-ivysettings">
<ivy:resolve file="ivy.xml" />
<ivy:publish
module="${ant.project.name}"
artifactspattern="${dist.dir}/[artifact].[ext]"
resolver="artifactory"
pubrevision="${build.version}-SNAPSHOT"
status="integration"
overwrite="true"
update="true"/>
</target>
这是详细说明解析器的 IVY 设置:
<sftp name="integration" checkmodified="true" changingPattern=".*" host="host" user="ivy" userPassword="abc">
<ivy pattern="${ivy.integration.default.root}/${ivy.public.default.ivy.pattern}"/>
<artifact pattern="${ivy.integration.default.root}/${ivy.public.default.artifact.pattern}"/>
</sftp>
<url name="artifactory" checkmodified="false" changingPattern=".*" m2compatible="true">
<ivy pattern="http://server/artifactory/libs-snapshot-local/${maven.default.ivy.pattern}"/>
<artifact pattern="http://server/artifactory/libs-snapshot-local/${maven.default.artifact.pattern}"/>
</url>
这种工作原理是我现在在 Artifactory 中看到通用库 jar,并用 SNAPSHOT 代替了唯一的时间戳。但是,源 jar 和 IVY xml 文件没有替换 SNAPSHOT。另外,没有生成 POM 文件(尽管我不知道这是否有必要)。
因此,这似乎没问题,尽管存在有关 POM 文件的需求以及 IVY xml 和源 jar 的版本命名的问题。但是,当我现在继续指定从 Maven 项目之一到公共库项目的 SNAPSHOT 版本之一的依赖关系时,它抱怨它无法解析该依赖关系:
缺少工件 com.smartstream.common_library:common_library_dao:jar:4.0.0.5-4-SNAPSHOT:compile
我尝试通过 POM 文件和 Maven 设置文件指定 Artifactory 的存储库,但收效甚微:
<repository>
<id>test</id>
<name>simple test</name>
<url>http://server/artifactory/libs-snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
奇怪的是,如果我让 IVY 发布一个版本,而不是在 Artifactory 的 libs-release-local 存储库中发布快照,所有这些都可以解决正如你所期望的。另外,如果我指定唯一时间戳作为依赖项版本的一部分(SNAPSHOT 的替代品),它也会解决它。因此,这表明 Maven 项目能够针对 Artifactory 进行解析,只是 SNAPSHOT 版本出现问题。
我已经从高处到低处进行了挖掘,对这个问题几乎没有希望。如果您能提供任何见解,我们将不胜感激。
We have a slight convoluted situation...
For the most part we've been using IVY and ANT to manage our builds and dependencies. Now the company is moving towards using Maven. We have a set of projects called common libraries which are used by several of the core products.
Common libraries use IVY and are published to an IVY repository. We also need to make common libraries available for our new Maven projects. So when common libraries get built and published, I've modified the script to publish to Maven (Artifactory) as well IVY. Here are the two targets that now get called when publishing the built IVY projects:
<target name="publish-ivyrepo" depends="load-ivysettings">
<ivy:resolve file="ivy.xml" />
<ivy:publish
module="${ant.project.name}"
artifactspattern="${dist.dir}/[artifact].[ext]"
resolver="integration"
pubrevision="${build.version}"
status="integration"
overwrite="true"
update="true"/>
</target>
<target name="publish-artifactory" depends="load-ivysettings">
<ivy:resolve file="ivy.xml" />
<ivy:publish
module="${ant.project.name}"
artifactspattern="${dist.dir}/[artifact].[ext]"
resolver="artifactory"
pubrevision="${build.version}-SNAPSHOT"
status="integration"
overwrite="true"
update="true"/>
</target>
And here is the IVY settings detailing the resolvers:
<sftp name="integration" checkmodified="true" changingPattern=".*" host="host" user="ivy" userPassword="abc">
<ivy pattern="${ivy.integration.default.root}/${ivy.public.default.ivy.pattern}"/>
<artifact pattern="${ivy.integration.default.root}/${ivy.public.default.artifact.pattern}"/>
</sftp>
<url name="artifactory" checkmodified="false" changingPattern=".*" m2compatible="true">
<ivy pattern="http://server/artifactory/libs-snapshot-local/${maven.default.ivy.pattern}"/>
<artifact pattern="http://server/artifactory/libs-snapshot-local/${maven.default.artifact.pattern}"/>
</url>
This kind of works in that I now see the common library jars within Artifactory, with SNAPSHOT substituted for the unique timestamp. However, the source jar and the IVY xml file doesn't have SNAPSHOT substituted. Also, no POM file is being generated (though I dont know if this is necessary.
So this appears to be okay, though there are questions around the need for the POM file and the version naming of the IVY xml and the source jar. However, when I now proceed to specify a dependency from one of the Maven projects to one of the SNAPSHOT versions of the common library projects, it complains that it cannot resolve the dependency:
Missing artifact com.smartstream.common_library:common_library_dao:jar:4.0.0.5-4-SNAPSHOT:compile
I've tried specifying the repositories to Artifactory via the POM file and via the Maven settings file will little success:
<repository>
<id>test</id>
<name>simple test</name>
<url>http://server/artifactory/libs-snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
What is strange is if I get IVY to publish a release as opposed to a SNAPSHOT into the libs-release-local repository of Artifactory, all resolves as you'd expect. Also, if I specify the unique timestamp as part of the dependency version (the substiute of SNAPSHOT), it also resolves it. So this shows that the Maven projects are able to resolve against Artifactory, just that something is going amiss with SNAPSHOT versions.
I've dug around high and low with little hope on this issue. If you can provide any insight, that'll be highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从ivy发布到Nexus存储库已在这里得到解答:
如何使用 ivy 和 Nexus 发布 3rdparty 工件
这个答案可能太全面了。相关部分的标题是“Ivy Solution”。我将在这里总结一下:
示例
ivy.xml
您需要一个出版物部分,说明您正在发布一个 jar 及其关联的 POM:
注意:
ivysettings.xml
我正在使用 ibiblio 解析器, Maven 2 兼容性已打开。根据我的经验,这是在 ivy 中配置 Maven 存储库的最佳方法。
注意:
build.xml
最后是构建逻辑本身。
注意:
任务在artifactory
Artifactory上似乎有一些对 ivy 的内置支持
Publishing to a Nexus repository from ivy has been answered here:
how to publish 3rdparty artifacts with ivy and nexus
That answer is possibly too comprehensive. The relevent section is titled "Ivy Solution". I'll summarise it here:
Example
ivy.xml
You'll need a publications section stating that you're publishing a jar and it's associated POM:
Notes:
ivysettings.xml
I'm using ibiblio resolvers, with Maven 2 compatibility switched on. In my experience this is the best way to configure a Maven repository in ivy.
Notes:
build.xml
Finally the build logic itself.
Notes:
Note on artifactory
Artifactory appears to have some built-in support for ivy
如果您已经打算迁移到 Maven,我建议您查看 Aether Ant 任务,它是旧的(现在几乎已弃用)Maven Ant 的替代品任务。使用它将暴露您的任务所需的所有 Maven 依赖项处理功能。
If you are already going to migrate to Maven I would suggest to check out the Aether Ant Tasks, which are the replacement for the old (and now pretty much deprecated) Maven Ant Tasks. Using that will be exposing all the needed Maven dependency handling features you need for your task..