我一直在寻找很长时间,试图找到解决我的问题的方法,但我遇到的所有其他帖子要么不起作用,要么不符合我的情况,所以希望有人能给我一些见解。
我有一个使用 ant 构建的库,它输出 2 个 jar 文件,一个正常包含库的编译版本,另一个仅包含源文件。
该库将上传到我们的 Nexus 存储库,并将打包设置为 jar。 对于实际的 jar 文件,我将扩展名设置为 jar 并将分类器留空。 对于源 jar,我将分类器设置为源,将扩展设置为 jar。
无论我如何处理我的常春藤.xml文件,我都无法让它下载源jar。 根据我在其他地方读过的帖子,我尝试添加:
conf="*->default,sources"
到我的依赖关系,但随后出现错误:
configuration not found in org#name;version: 'sources'
所以这基本上是期望我的库将源定义为某处的配置? 我以为它只会发现另一个工件将分类器设置为存储库中的源。
谁能给我其他建议,说明我可能做错了什么,无论是我将库发布到 Nexus 的方式,还是我在常春藤文件中设置依赖声明的方式。
这是基本的常春藤.xml文件,我在其中定义了我对Nexus中库的依赖关系。
<ivy-module version="2.0">
<info organisation="${ivy.organisation}" module="moduleName" />
<configurations>
<conf name="pda" description="moduleName for PDA"/>
<conf name="server" description="moduleName for server"/>
</configurations>
<dependencies>
<!-- Internal -->
<dependency name="utility" org="${ivy.organisation}" rev="latest.integration" conf="${ivy.configuration}"/>
<dependency name="myLib" org="my.org" rev="0.0.+"/>
</dependencies>
</ivy-module>
为了回应下面的评论,ivy.configuration 属性在我的 Ant 的 build.properties 中设置为 pda。 对于 Eclipse,我创建了一个属性文件,并将 ivy.configuration 设置为 pda(然后在 Eclipse 的 Ivy 设置中引用此属性文件)。
我收到的错误消息是:
Some projects fail to be resolved
Impossible to resolve dependencies of ${ivy.organisation}#moduleName;working@host
unresolved dependency: my.org#myLib;0.0.+: configuration not found in my.org#myLib;0.0.0: 'sources'. It was required from ${ivy.organisation}#moduleName;working@host pda
更新这是解析的常春藤.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0">
<info organisation="my.org"
module="myLib"
revision="0.0.0"
status="release"
publication="20120419131909"
default="true"
/>
<configurations>
<conf name="default" visibility="public"/>
</configurations>
<publications>
<artifact name="myLib" type="jar" ext="jar" conf="default"/>
</publications>
</ivy-module>
这显然解释了为什么它找不到"来源"conf。 但我的印象是应该自动添加源 conf,因为我已将源添加到 Nexus。
发布项目时,应告知 Ivy 有关配置的信息。例如:
<ivy-module version="2.0">
<info organisation="apache" module="commons-lang" revision="2.5" status="release"/>
<configurations>
<conf name="binary" description="provide only binary files"/>
<conf name="development" extends="binary" description="provide binary files with javadoc and sources"/>
</configurations>
<publications>
<artifact name="commons-lang" ext="jar" conf="binary" type="jar"/>
<artifact name="commons-lang-javadoc" ext="jar" conf="development" type="javadoc"/>
<artifact name="commons-lang-sources" ext="jar" conf="development" type="source"/>
</publications>
</ivy-module>
如您所见,commons-lang.jar在二进制配置下发布。但是 commons-lang-sources 和 commons-lang-javadoc 在开发配置下发布。
检索依赖项时,应使用以下常春藤.xml:
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
<info organisation="bitrete" module="strongpoint" status="development"/>
<configurations>
<conf name="binary" description="provide only binary files"/>
<conf name="development" extends="binary" description="provide binary files with javadoc and sources"/>
</configurations>
<publications>
<artifact name="strongpoint" ext="jar" type="jar"/>
</publications>
<dependencies>
<dependency org="apache" name="commons-lang" rev="2.5"/>
</dependencies>
</ivy-module>
并在使用 Ant 解析时提供所需的配置:
<property name="ivy.conf" value="binary"/>
...
<property name="ivy.conf" value="development"/>
...
<ivy:resolve conf="${ivy.conf}"/>
所以经过很多玩法,我似乎终于有了解决这个问题的方法。 如果我通过以下方式声明我的依赖关系:
<dependency name="myLib" org="my.org" rev="0.0.+">
<artifact type="jar"/>
<artifact type="source" m:classifier="sources" conf="pdaDev->sources"/>
</dependency>
然后我可以添加一个新配置(例如上面的 pdaDev),它链接到依赖项的源配置。 当使用Eclipse时,我可以告诉它使用pdaDev配置,它也确实拉入了源jar(如果存在的话)。
奇怪的是,Nexus似乎没有在解析的常春藤文件中包含源配置,除非像我上面所做的那样明确要求。
在 ivy 文件中创建两个配置。一个用于应位于类路径中的二进制文件,另一个用于源 jar。
其次,在依赖项上创建两个配置映射:
<ivy-module version="2.0">
<info organisation="org.demo" module="demo"/>
<configurations>
<conf name="compile" description="jars used for compilation classpath"/>
<conf name="sources" description="Source jars"/>
</configurations>
<dependencies>
<dependency org="org.slf4j" name="slf4j-simple" rev="1.6.4" conf="compile->default;sources->sources"/>
</dependencies>
</ivy-module>
注意:
- Maven模块由ivy翻译为具有一组标准的配置。有关更多详细信息,请参阅常春藤如何将 maven 范围映射到常春藤配置
在 ANT 构建中,您可以按如下方式使用这些配置:
<target name="init">
<ivy:resolve/>
<!-- Populate a compile classpath for use with javac task -->
<ivy:cachepath pathid="compile.path" conf="compile"/>
<!-- Put source jars in the src directory -->
<ivy:retrieve pattern="src/[artifact]-[revision](-[classifier]).[ext]" conf="sources"/>
</target>