Junit 为*.jar文件指定渐变依赖项

Junit 为*.jar文件指定渐变依赖项,junit,jar,dependencies,gradle,Junit,Jar,Dependencies,Gradle,这必须是直截了当的,但我看不出特定jar文件的group:name:和version:来自何处。例如,来自Gradle的文档 dependencies { compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final' testCompile group: 'junit', name: 'junit', version: '4.+' testRuntime "org.hamcre

这必须是直截了当的,但我看不出特定jar文件的group:name:和version:来自何处。例如,来自Gradle的文档

dependencies {
    compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'
    testCompile group: 'junit', name: 'junit', version: '4.+'
    testRuntime "org.hamcrest:SelfDescribing:1.+"
}
我正在尝试使用hamcrest jar进行junit测试。我需要hamcrest进行运行时测试,但我不知道如何正确地指定它。下面是我的build.gradle文件。此测试项目将成功生成,但由于未解析的依赖关系,将不会运行单元测试

apply plugin: 'java'
apply plugin: 'eclipse-wtp'

version = '1.0'

compileJava.destinationDir = file("$buildDir/classes/test")

sourceSets {
    main {
        java {
            srcDir 'src'
        }
    }
}

repositories {
flatDir dirs: "C:/eclipse/plugins/org.junit_4.11.0.v201303080030"
flatDir dirs: "C:/eclipse/plugins"
}

dependencies {
compile "junit:junit:4"
testCompile "junit:junit:4"
testRuntime "org.hamcrest:SelfDescribing:1.+"
}

test {
testLogging.showStandardStreams = true

testLogging {
    events 'started', 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
    exceptionFormat 'short'
}
}

jar {
manifest.attributes provider: 'gradle'
}

要在jar文件上添加依赖项,请在
dependencies
块中添加如下语句:

compile files('path/to/archive.jar')
一种流行的方法是这样的,它将自动拾取libs目录中的所有jar文件:

compile fileTree(dir: 'path/to/libs', include: '*.jar')

要在jar文件上添加依赖项,请在
dependencies
块中添加如下语句:

compile files('path/to/archive.jar')
一种流行的方法是这样的,它将自动拾取libs目录中的所有jar文件:

compile fileTree(dir: 'path/to/libs', include: '*.jar')

要在jar文件上添加依赖项,请在
dependencies
块中添加如下语句:

compile files('path/to/archive.jar')
一种流行的方法是这样的,它将自动拾取libs目录中的所有jar文件:

compile fileTree(dir: 'path/to/libs', include: '*.jar')

要在jar文件上添加依赖项,请在
dependencies
块中添加如下语句:

compile files('path/to/archive.jar')
一种流行的方法是这样的,它将自动拾取libs目录中的所有jar文件:

compile fileTree(dir: 'path/to/libs', include: '*.jar')

使用
flatDir
存储库时,您必须确保:

  • 工件文件直接包含在指定的目录中(不在子目录中)
  • 工件文件名与模式
    module version.extension
    (例如
    junit-4.jar
    )或
    module.extension
    (例如
    junit.jar
    )匹配
或者,您可以使用Scott回答中描述的
文件
依赖项


PS:我不确定版本范围是否适用于
flatDir
存储库。

使用
flatDir
存储库时,您必须确保:

  • 工件文件直接包含在指定的目录中(不在子目录中)
  • 工件文件名与模式
    module version.extension
    (例如
    junit-4.jar
    )或
    module.extension
    (例如
    junit.jar
    )匹配
或者,您可以使用Scott回答中描述的
文件
依赖项


PS:我不确定版本范围是否适用于
flatDir
存储库。

使用
flatDir
存储库时,您必须确保:

  • 工件文件直接包含在指定的目录中(不在子目录中)
  • 工件文件名与模式
    module version.extension
    (例如
    junit-4.jar
    )或
    module.extension
    (例如
    junit.jar
    )匹配
或者,您可以使用Scott回答中描述的
文件
依赖项


PS:我不确定版本范围是否适用于
flatDir
存储库。

使用
flatDir
存储库时,您必须确保:

  • 工件文件直接包含在指定的目录中(不在子目录中)
  • 工件文件名与模式
    module version.extension
    (例如
    junit-4.jar
    )或
    module.extension
    (例如
    junit.jar
    )匹配
或者,您可以使用Scott回答中描述的
文件
依赖项


PS:我不确定版本范围是否适用于
flatDir
存储库。

此响应解决了我的问题,但仅部分正确。我需要这个罐子来运行。所以我指定了运行时而不是编译。谢谢这个回答解决了我的问题,但只是部分正确。我需要这个罐子来运行。所以我指定了运行时而不是编译。谢谢这个回答解决了我的问题,但只是部分正确。我需要这个罐子来运行。所以我指定了运行时而不是编译。谢谢这个回答解决了我的问题,但只是部分正确。我需要这个罐子来运行。所以我指定了运行时而不是编译。谢谢