gpt4 book ai didi

java - 在Gradle中使用 cucumber 时在运行时添加必要的库文件

转载 作者:行者123 更新时间:2023-12-03 03:54:26 24 4
gpt4 key购买 nike

我们在开发过程中使用Cucumber在AWS中构建服务。我们正在使用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的配置,例如在docs中:

configurations {
cucumberRuntime {
extendsFrom testImplementation
}
}

然后只需将文件夹添加到配置中,如下所示:
dependencies {
cucumberRuntime(fileTree('build/dyanamodb-local'))
}

它应该可以解决问题。

可以考虑使用 amazon/dynamodb-local Docker镜像或 LocalStack而不是污染您的依赖项。

关于java - 在Gradle中使用 cucumber 时在运行时添加必要的库文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62223501/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com