Gradle无法在〜/ .ivy2 / local中找到我的依赖项

时间:2015-02-25 07:38:22

标签: gradle dependencies ivy

我使用sbt publishLocal将一些自定义库发布到~/.ivy2/local。之后,目录结构为:

$ pwd
/Users/twer/.ivy2/local/com.thoughtworks
$ tree .
.
└── pact-jvm-provider-spring-mvc_2.11
    └── 0.1
        ├── docs
        │   ├── pact-jvm-provider-spring-mvc_2.11-javadoc.jar
        │   ├── pact-jvm-provider-spring-mvc_2.11-javadoc.jar.md5
        │   └── pact-jvm-provider-spring-mvc_2.11-javadoc.jar.sha1
        ├── ivys
        │   ├── ivy.xml
        │   ├── ivy.xml.md5
        │   └── ivy.xml.sha1
        ├── jars
        │   ├── pact-jvm-provider-spring-mvc_2.11.jar
        │   ├── pact-jvm-provider-spring-mvc_2.11.jar.md5
        │   └── pact-jvm-provider-spring-mvc_2.11.jar.sha1
        ├── poms
        │   ├── pact-jvm-provider-spring-mvc_2.11.pom
        │   ├── pact-jvm-provider-spring-mvc_2.11.pom.md5
        │   └── pact-jvm-provider-spring-mvc_2.11.pom.sha1
        └── srcs
            ├── pact-jvm-provider-spring-mvc_2.11-sources.jar
            ├── pact-jvm-provider-spring-mvc_2.11-sources.jar.md5
            └── pact-jvm-provider-spring-mvc_2.11-sources.jar.sha1

7 directories, 15 files

然后我创建了一个gradle项目,其中包含一个简单的build.gradle文件:

apply plugin: 'java'
apply plugin: 'idea'

repositories {
    ivy {
        url "${System.properties['user.home']}/.ivy2/local"
        layout 'ivy'
    }
}

dependencies {
    compile(
            "com.thoughtworks:pact-jvm-provider-spring-mvc_2.11:0.1"
    )
    testCompile(
        'junit:junit:4.11'
    )
}

当我运行gradle compileJava时,它会报告错误:

:compileJava

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all dependencies for configuration ':compile'.
> Module version :test-gradle-with-local-ivy:unspecified, configuration 'compile' declares a dependency on configuration 'default' which is not declared in the module descriptor for com.thoughtworks:pact-jvm-provider-spring-mvc_2.11:0.1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 3.306 secs

错在哪里以及如何解决?


我意识到ivy.xml / pom.xml的内容可能很有用,所以我也在这里添加了它们:

ivys /的ivy.xml

<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0" xmlns:e="http://ant.apache.org/ivy/extra">
    <info organisation="com.thoughtworks" module="pact-jvm-provider-spring-mvc_2.11" revision="0.1" status="release" publication="20150225152253">
        <description>
        pact-jvm-provider-spring-mvc
        </description>
    </info>
    <configurations>
        <conf name="compile" visibility="public" description=""/>
        <conf name="runtime" visibility="public" description="" extends="compile"/>
        <conf name="test" visibility="public" description="" extends="runtime"/>
        <conf name="provided" visibility="public" description=""/>
        <conf name="optional" visibility="public" description=""/>

        <conf name="sources" visibility="public" description=""/>
        <conf name="docs" visibility="public" description=""/>
        <conf name="pom" visibility="public" description=""/>

    </configurations>
    <publications>
        <artifact name="pact-jvm-provider-spring-mvc_2.11" type="pom" ext="pom" conf="pom"/>
        <artifact name="pact-jvm-provider-spring-mvc_2.11" type="jar" ext="jar" conf="compile"/>
        <artifact name="pact-jvm-provider-spring-mvc_2.11" type="src" ext="jar" conf="sources" e:classifier="sources"/>
        <artifact name="pact-jvm-provider-spring-mvc_2.11" type="doc" ext="jar" conf="docs" e:classifier="javadoc"/>
    </publications>

    <dependencies>
        <dependency org="org.scala-lang" name="scala-library" rev="2.11.0" conf="compile->default(compile)"/>
        <dependency org="au.com.dius" name="pact-jvm-model_2.11" rev="2.1.11" conf="compile->default(compile)"/>
        <dependency org="au.com.dius" name="pact-jvm-consumer-junit_2.11" rev="2.1.10" conf="compile->default(compile)"/>
        <dependency org="org.springframework" name="spring-test" rev="4.1.3.RELEASE" conf="compile->default(compile)"/>
        <dependency org="org.springframework" name="spring-webmvc" rev="4.1.3.RELEASE" conf="compile->default(compile)"/>
        <dependency org="org.springframework" name="spring-context" rev="4.1.3.RELEASE" conf="compile->default(compile)"/>
        <dependency org="org.springframework" name="spring-core" rev="4.1.3.RELEASE" conf="compile->default(compile)"/>
        <dependency org="junit" name="junit" rev="4.12" conf="compile->default(compile)"/>
        <dependency org="javax.servlet" name="javax.servlet-api" rev="3.0.1" conf="compile->default(compile)"/>
        <dependency org="org.mockito" name="mockito-core" rev="1.9.5" conf="compile->default(compile)"/>
        <dependency org="org.specs2" name="specs2_2.11" rev="2.4.2" conf="test->default(compile)"/>
    </dependencies>
</ivy-module>

POMS /协议-JVM-提供商 - 弹簧 - mvc_2.11.pom

<?xml version='1.0' encoding='UTF-8'?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.thoughtworks</groupId>
    <artifactId>pact-jvm-provider-spring-mvc_2.11</artifactId>
    <packaging>jar</packaging>
    <description>pact-jvm-provider-spring-mvc</description>
    <version>0.1</version>
    <name>pact-jvm-provider-spring-mvc</name>
    <organization>
        <name>com.thoughtworks</name>
    </organization>
    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>2.11.0</version>
        </dependency>
        <dependency>
            <groupId>au.com.dius</groupId>
            <artifactId>pact-jvm-model_2.11</artifactId>
            <version>2.1.11</version>
        </dependency>
        <dependency>
            <groupId>au.com.dius</groupId>
            <artifactId>pact-jvm-consumer-junit_2.11</artifactId>
            <version>2.1.10</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>4.1.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.1.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.1.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.1.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>1.9.5</version>
        </dependency>
        <dependency>
            <groupId>org.specs2</groupId>
            <artifactId>specs2_2.11</artifactId>
            <version>2.4.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <repositories>
        <repository>
            <id>ibiblio</id>
            <name>ibiblio</name>
            <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
            <layout>default</layout>
        </repository>
        <repository>
            <id>Sonatypesnapshots</id>
            <name>Sonatype snapshots</name>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
            <layout>default</layout>
        </repository>
        <repository>
            <id>Sonatypereleases</id>
            <name>Sonatype releases</name>
            <url>http://oss.sonatype.org/content/repositories/releases/</url>
            <layout>default</layout>
        </repository>
        <!-- more repositories ignored here -->
    </repositories>
</project>

1 个答案:

答案 0 :(得分:3)

ivy.xml生成的sbt publishLocal没有default配置,其所有依赖项都使用compiletest配置。

因此,当我在另一个项目中使用它时,我必须明确声明配置,例如:

compile group: "com.thoughtworks", name: "pact-jvm-provider-spring-mvc_2.11", version: "0.1", configuration: 'compile'

注意configuration: 'compile'部分。

现在一切都好。