Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
689 views
in Technique[技术] by (71.8m points)

ant - Ivy makepom marks all dependencies as optional despite mapping

Given:

<dependency org="foo" name="bar" />

and no configurations, following ant snippet:

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

Produces pom with with optional dependency on foo.bar and prints "default". If I change mapping to conf="*" then it works but it is obviously suboptimal.

Is it possible to map unspecified default configuration or do I need to set conf="default" on all dependencies in ivy.xml ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The optional dependency mapping appears to be the default behaviour.

Ivy is not restricted to a fixed number of scopes. While ivy configurations are much more flexible, you cannot assume that each configuration is being use to populate standard project classpaths....

The safest thing to do is provide an explicit mapping of each ivy configuration to the matching scope in Maven. In practice I recommend creating an ivy configuration to to emulate each Maven scope (regardless of whether it's used or not).

   <target name="generate-pom" depends="resolve" description="Generate Maven POM">
      <ivy:deliver deliverpattern="${build.dir}/ivy.xml" pubrevision="${project.version}"/>

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

Note:

  • You omitted the deliver ivy task. Necessary to ensure that ivy dynamic revisions are resolved and that the ivy module has a revision tag set to expected published revision number. (Unlike Maven you don't need to edit the ivy file to increment a module version).

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...