Java 在gradle中使用cucumber时,在运行时添加必要的库文件

Java 在gradle中使用cucumber时,在运行时添加必要的库文件,java,gradle,amazon-dynamodb,cucumber,Java,Gradle,Amazon Dynamodb,Cucumber,我们在AWS中构建服务的开发过程中使用Cucumber。我们使用的是DynamoDb,当我们在本地运行测试时,我们使用的是DynamoDb的本地实例。为此,我们需要在类路径中包含某些库文件。我们在gradle的测试任务中设法做到了这一点,但在cucumber任务中却没有做到 考虑到这些文件位于我们项目中的文件夹build/dyanamodb local,有没有办法将它们包含在cucumber任务的类路径中 build.gradle文件: plugins { id 'java' i

我们在AWS中构建服务的开发过程中使用Cucumber。我们使用的是DynamoDb,当我们在本地运行测试时,我们使用的是DynamoDb的本地实例。为此,我们需要在类路径中包含某些库文件。我们在gradle的测试任务中设法做到了这一点,但在cucumber任务中却没有做到

考虑到这些文件位于我们项目中的文件夹
build/dyanamodb local
,有没有办法将它们包含在cucumber任务的类路径中

build.gradle文件:

plugins {
    id 'java'
    id 'jacoco'
    id 'checkstyle'
    id 'pmd'

}

repositories {
    jcenter()
    maven { url 'https://jitpack.io' }
    maven { url "https://s3.eu-central-1.amazonaws.com/dynamodb-local-frankfurt/release" }
}


def jacksonVersion = "2.10.3"
def jupiterVersion = "5.6.0"
def awsSdkVersion = "1.11.791"

apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'checkstyle'
apply plugin: 'pmd'

configurations.testImplementation.canBeResolved = true
configurations {
    cucumberRuntime {
        extendsFrom testImplementation
    }
}

dependencies {
    implementation group: 'com.amazonaws', name: 'aws-lambda-java-core', version: '1.2.0'
    implementation group: 'com.amazonaws', name: 'aws-lambda-java-events', version: '2.2.7'
    implementation group: 'com.amazonaws', name: 'aws-java-sdk-lambda', version: awsSdkVersion
    implementation group: 'com.amazonaws', name: 'aws-java-sdk-dynamodb', version: awsSdkVersion

    implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jdk8', version: jacksonVersion
    implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: jacksonVersion
    implementation group: 'com.fasterxml.jackson.module', name: 'jackson-module-parameter-names', version: jacksonVersion

    implementation group: 'com.github.BIBSYSDEV', name: 'nva-commons', version: '0.3.5'

    testImplementation group: 'com.amazonaws', name: 'DynamoDBLocal', version: '1.12.0'
    testImplementation group: 'com.almworks.sqlite4java', name: 'sqlite4java', version: '1.0.392'

    testImplementation group: 'io.cucumber', name: 'cucumber-java', version: '5.6.0'
    testImplementation group: 'io.cucumber', name: 'cucumber-picocontainer', version: '5.6.0'
    testImplementation group: 'io.cucumber', name: 'cucumber-junit', version: '5.6.0'
    testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: jupiterVersion
    testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '2.2'
}

task copyNativeDeps(type: Copy) {
    from(configurations.testImplementation) {
        include "*.dylib"
        include "*.so"
        include "*.dll"
    }
    into 'build/dynamodb-local'
}

test.dependsOn copyNativeDeps
test.doFirst {
    systemProperty "java.library.path", 'build/dynamodb-local'
}

test {
    useJUnitPlatform()
    failFast = true
    testLogging {
        events 'skipped', 'passed', 'failed'
    }
    finalizedBy jacocoTestReport
}

task cucumber() {
    dependsOn assemble, compileTestJava
    doLast {
        javaexec {
            main = "io.cucumber.core.cli.Main"
            classpath = configurations.cucumberRuntime+ configurations.testImplementation + sourceSets.main.output + sourceSets.test.output
            args = ['--plugin', 'pretty', '--glue', 'features', 'src/test/resources']
        }
    }
}




编辑:我混合了类路径和库路径。我需要的是编辑库路径。但是,如果需要编辑类路径,我建议查看@madhead提供的解决方案,我假设您有Cucumber的配置,如文档中所示:

configurations {
    cucumberRuntime {
        extendsFrom testImplementation
    }
}
然后只需向配置中添加一个文件夹,如:

dependencies {
    cucumberRuntime(fileTree('build/dyanamodb-local'))
}
它应该会起作用


< >不要污染您的依赖关系,请考虑使用DOCKER图像或.< /P> < P>我通过在CuthJava>的代码> javaExc>/Cult>配置中添加Stand属性来实现它。现在的任务如下所示:

task cucumber() {
    dependsOn assemble, compileTestJava
    doLast {
        javaexec {
            main = "io.cucumber.core.cli.Main"
            systemProperties =[ "java.library.path" :'build/dynamodb-local']
            classpath = configurations.cucumberRuntime+ configurations.testImplementation + sourceSets.main.output + sourceSets.test.output
            args = ['--plugin', 'pretty', '--glue', 'features', 'src/test/resources']
        }
    }
}


谢谢:)依赖项替代方案不起作用。我将考虑剩下的解决方案,这不是“类路径”,这是一个图书馆路径:(谢谢你把它带到我的注意。我编辑了最初的问题,为清晰起见。