简体   繁体   English

使用 ivy 将多个工件发布到 Maven 存储库

[英]Publishing multiple artifacts to maven repository using ivy

I published few atifacts of a component to a maven repository using different configurations of ivy.我使用不同的 ivy 配置将组件的一些 atifacts 发布到 Maven 存储库。 As an example, I took the following way ( Ivy Documentation ) to do the same..例如,我采用以下方式( 常春藤文档)来做同样的事情..

<ivy-module version="1.0">
<info organisation="org.apache" module="filter"/>
<configurations>
<conf name="api"  description="only provide filter framework API"/>
<conf name="homemade-impl" extends="api" description="provide a home made implementation of our api"/>
</configurations>

<publications>
    <artifact name="filter-api" type="jar"  conf="api" ext="jar"/>
    <artifact name="filter-hmimpl" type="jar"  conf="homemade-impl" ext="jar"/>      
</publications>

</ivy-module>

According to the above configuration, the artifacts that are produced are filter-api.jar and filter-hmimpl.jar , and I generated a pom file filter.pom and published this into a maven repository.根据上面的配置,生成的artifact是filter-api.jarfilter-hmimpl.jar ,我生成了一个pom文件filter.pom ,发布到m​​aven仓库中。

Now, when I am trying to resolve the artifact filter-api in another component using the following..现在,当我尝试使用以下内容解析另一个组件中的工件过滤器 API时..

    <dependency org="org.apache" name="filter" rev="3.1" conf="default->api"/>

But it is not working, I believe my filter.pom should contain some modules like this, to make it work..但它不起作用,我相信我的 filter.pom 应该包含一些这样的模块,以使其工作..

    <modules>
       <module>api</module> 
       <module>homemade-impl</module> 
    </modules>

Am I correct, and if yes how can I map different conf's of ivy to modules in maven.我是否正确,如果是,如何将 ivy 的不同 conf 映射到 maven 中的模块。

Publishing mutliple files to a Maven repository is tricky because Maven modules normally contain a single artifact.将多个文件发布到 Maven 存储库很棘手,因为 Maven 模块通常包含单个工件。 Maven modules do support additional module artifacts, which are referenced in a Maven dependency using the "classifier" attribute. Maven 模块确实支持其他模块工件,这些工件在 Maven 依赖项中使用“分类器”属性进行引用。

The following answers provide examples of publishing multiple files to a Maven module:以下答案提供了将多个文件发布到 Maven 模块的示例:

Observe that the ANT scripts are using the makepom to generate POM files and that these files are considered artifacts published (part of the ivy publications section).观察到 ANT 脚本正在使用makepom生成 POM 文件,并且这些文件被视为已发布的工件(常春藤出版物部分的一部分)。

For more background you might be interested in the following answer that deals with the differences between Maven "scopes" and ivy "confgurations".有关更多背景信息,您可能对以下处理 Maven“范围”和常春藤“配置”之间差异的答案感兴趣。

Finally, if your ivy build uses configurations, it's possible to configure the makepom task to map between configurations and scopes:最后,如果您的 ivy 构建使用配置,则可以配置makepom任务以在配置和范围之间进行映射:

<ivy:makepom ivyfile="${build.dir}/ivy.xml" pomfile="${build.dir}/${ivy.module}.pom"/>
   <mapping conf="api" scope="compile"/>
</ivy:makepom>

Most likely, the problem is with the dependency declaration.最有可能的问题是依赖声明。 You pull the dependency into your 'default' configuration with conf="default->api".您使用 conf="default->api" 将依赖项拉入您的“默认”配置中。 But you really want them in the "compile" conf, to include them in your compile classpath.但是您真的希望它们在“编译”conf 中,以将它们包含在您的编译类路径中。

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

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