常春藤似乎只能获取javadoc罐子

时间:2011-02-13 04:52:30

标签: java ivy

我在我的项目中使用Ivy,使用Ivy Eclipse插件。

看来,下载并添加到我项目中的某些罐子是javadoc罐子,而不是带有实际代码的罐子。注意 - 所有罐子都不会发生这种情况。

例如,将其添加到我的ivy.xml文件中:

<dependency org="junit" name="junit" rev="4.8.2"/>

导致junit的javadocs被下载并添加到我的类路径中: enter image description here

这打破了我的项目的编译,因为没有任何单元测试正在运行。

这个工作正常,直到我添加了对Spring的引用,一切都破了。我已经尝试删除引用,并从我的本地缓存中删除junit以强制常春藤再次获取它,但问题仍然存在。

这是我的总依赖块(删除了弹簧):

<dependencies>
    <dependency org="org.hamcrest" name="hamcrest-library" rev="1.3.RC2"/>
    <dependency org="junit" name="junit" rev="4.8.2"/>
    <dependency org="org.mockito" name="mockito-core" rev="1.8.5"/>
    <dependency org="javax.persistence" name="persistence-api" rev="1.0"/>
</dependencies>

这是项目的ivysettings.xml

<ivysettings>

    <caches artifactPattern="[organisation]/[module]/[revision]/[artifact].[ext]" />
    <settings defaultResolver="local.ibiblio.jboss.java-net.springsource" checkUpToDate="true" />

    <resolvers>
        <chain name="local.ibiblio.jboss.java-net.springsource">
            <filesystem name="libraries">
                <artifact pattern="${basedir}/ivy-repo/[artifact]-[revision].[type]" />
            </filesystem>
            <ibiblio name="ibiblio" m2compatible="true" />
            <ibiblio name="jboss" m2compatible="true"
                root="https://repository.jboss.org/nexus/content/groups/public-jboss" />
            <ibiblio name="java.net" m2compatible="true"
                root="https://repository.jboss.org/nexus/content/repositories/java.net-m2/" />
            <ibiblio name="java.net" m2compatible="true"
                root="http://repository.codehaus.org/" />
            <url name="com.springsource.repository.libraries.release">
                <ivy pattern="http://repository.springsource.com/ivy/libraries/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
                <artifact pattern="http://repository.springsource.com/ivy/libraries/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
            </url>

            <url name="com.springsource.repository.libraries.external">
                <ivy pattern="http://repository.springsource.com/ivy/libraries/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
                <artifact pattern="http://repository.springsource.com/ivy/libraries/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
            </url>
            <url name="com.springsource.repository.bundles.release">
                <ivy pattern="http://repository.springsource.com/ivy/bundles/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
                <artifact pattern="http://repository.springsource.com/ivy/bundles/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
            </url>

            <url name="com.springsource.repository.bundles.external">
                <ivy pattern="http://repository.springsource.com/ivy/bundles/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
                <artifact pattern="http://repository.springsource.com/ivy/bundles/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
            </url>
        </chain>

    </resolvers>
</ivysettings>

1 个答案:

答案 0 :(得分:12)

一些开源模块包括可选的java doc jar。要删除它们,请为每个依赖项添加配置映射:

   <dependency org="junit" name="junit" rev="4.8.2" conf="default"/>

ivy中的默认配置相当于maven模块中的编译范围。这是可以自动省略可选库的方式。 (检查他们的POM)。

更好的方法是声明您自己的配置和默认映射,如下所示:

<configurations defaultconfmapping="compile->default">
   <conf name="compile" description="Required to compile code"/>
   <conf name="test" description="Additional test dependencies" extends="compile" />
</configurations>

然后在您的常春藤文件中,您只需要声明非标准配置:

<dependencies>
    <dependency org="org.hamcrest" name="hamcrest-library" rev="1.3.RC2" conf="test->default"/>
    <dependency org="junit" name="junit" rev="4.8.2" conf="test->default"/>
    <dependency org="org.mockito" name="mockito-core" rev="1.8.5" conf="test->default"/>
    <dependency org="javax.persistence" name="persistence-api" rev="1.0"/>
</dependencies>

在这种情况下,我们只希望3个测试库出现在测试配置中。

仍然困惑?常春藤配置的神奇之处在于,当您使用它们来管理构建的类路径时

  <target name='dependencies' description='Resolve project dependencies and set classpaths'>
    <ivy:resolve/>

    <ivy:cachepath pathid="compile.path"  conf="compile"/>
    <ivy:cachepath pathid="test.path"     conf="test"/>
  </target>

这是Maven在依赖项上声明范围标记时正在执行的操作,例如:

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.8.2</version>
    <scope>test</scope>
</dependency>

Maven中的范围是固定的。在常春藤,你可以拥有你需要的任何数量。

相关问题