简体   繁体   中英

Publishing multiple artifacts to maven repository using ivy

I published few atifacts of a component to a maven repository using different configurations of ivy. 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.

Now, when I am trying to resolve the artifact filter-api in another component using the following..

    <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..

    <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.

Publishing mutliple files to a Maven repository is tricky because Maven modules normally contain a single artifact. Maven modules do support additional module artifacts, which are referenced in a Maven dependency using the "classifier" attribute.

The following answers provide examples of publishing multiple files to a Maven module:

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).

For more background you might be interested in the following answer that deals with the differences between Maven "scopes" and ivy "confgurations".

Finally, if your ivy build uses configurations, it's possible to configure the makepom task to map between configurations and scopes:

<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". But you really want them in the "compile" conf, to include them in your compile classpath.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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