我正在尝试在本地运行 DynamoDB 以进行测试.我按照亚马逊提供的步骤设置它并自行运行 jar 可以正常工作(链接到亚马逊的教程 这里).但是,本教程不会在您自己的项目中运行 jar.我不希望所有其他开发人员每次测试代码时都必须获取一个 jar 并在本地运行它.
这就是我的问题所在.作为我的测试的一部分,我很难在网上找到任何关于如何配置 Gradle 项目以运行 DynamoDB 本地服务器的示例.我找到了以下 maven 示例 https://github.com/awslabs/aws-dynamodb-examples/blob/master/src/test/java/com/amazonaws/services/dynamodbv2/DynamoDBLocalFixture.java#L32 并且正在尝试将其转换为 Gradle,但他们正在使用的所有 com.amazonaws.services.dynamodbv2.local
导入语句都出现错误.错误是找不到资源.
我进入他们项目的 pom 并将以下内容放入我的 build.gradle
文件中以模拟它.
//dynamodb 本地依赖testCompile('com.amazonaws:aws-java-sdk-dynamodb:1.10.42')testCompile('com.amazonaws:aws-java-sdk-cloudwatch:1.10.42')testCompile('com.amazonaws:aws-java-sdk:1.3.0')testCompile('com.amazonaws:amazon-kinesis-client:1.6.1')testCompile('com.amazonaws:amazon-kinesis-connectors:1.1.1')testCompile('com.amazonaws:dynamodb-streams-kinesis-adapter:1.0.2')testCompile('com.amazonaws:DynamoDBLocal:1.10.5.1')
导入语句仍然失败.这是一个失败的例子.
import com.amazonaws.services.dynamodbv2.local.embedded.DynamoDBEmbedded;
TL;DR
有没有人设法让 DynamoDB 本地 JAR 作为 Gradle 项目的一部分执行,或者有一个好的教程链接(不一定是我链接到的教程).
我们有 DynamoDB 本地使用 gradle.以下是您需要添加到 gradle.build 文件中的内容:
适用于 gradle 4.x 及以下版本
1) 添加到存储库部分:
行家 {网址http://dynamodb-local.s3-website-us-west-2.amazonaws.com/release"}
2) 添加到依赖项部分(假设您将其用于测试):
testCompile 组:'com.amazonaws',名称:'DynamoDBLocal',版本:1.11.0
3) 接下来的两个步骤是棘手的部分.首先将本机文件复制到一个目录:
任务 copyNativeDeps(type: Copy) {来自(configurations.testCompile){包括*.dylib"包括*.so"包括*.dll"}进入构建/库"}
4) 然后确保在 java 库路径中包含这个目录(在我们的例子中是 build/libs):
test.dependsOn copyNativeDeps测试.doFirst {系统属性java.library.path",构建/库"}
现在您应该能够运行 ./gradlew test 并让您的测试进入您的本地 DynamoDB.
I am trying to run DynamoDB local for testing purposes. I followed the steps amazon provides for setting it up and running the jar by itself works fine (link to amazon's tutorial Here). However, the tutorial doesn't go over running the jar within your own project. I don't want all the other developers to have to grab a jar and run it locally every time they test their code.
That is where my question comes in. I've had a real hard time finding any examples online of how to configure a Gradle project to run the DynamoDB local server as part of my tests. I found the following maven example https://github.com/awslabs/aws-dynamodb-examples/blob/master/src/test/java/com/amazonaws/services/dynamodbv2/DynamoDBLocalFixture.java#L32 and am trying to convert it to a Gradle, but am getting errors for all of com.amazonaws.services.dynamodbv2.local
import statements they are using. The errors are that the resource cannot be found.
I went into their project's pom and put the following into my build.gradle
file to emulate it.
//dynamodb local dependencies testCompile('com.amazonaws:aws-java-sdk-dynamodb:1.10.42') testCompile('com.amazonaws:aws-java-sdk-cloudwatch:1.10.42') testCompile('com.amazonaws:aws-java-sdk:1.3.0') testCompile('com.amazonaws:amazon-kinesis-client:1.6.1') testCompile('com.amazonaws:amazon-kinesis-connectors:1.1.1') testCompile('com.amazonaws:dynamodb-streams-kinesis-adapter:1.0.2') testCompile('com.amazonaws:DynamoDBLocal:1.10.5.1')
The import statements still fail. Here is an example of one that fails.
import com.amazonaws.services.dynamodbv2.local.embedded.DynamoDBEmbedded;
TL;DR
Has anyone managed to get the DynamoDB local JAR to execute as part of a Gradle project or have a link to a good tutorial (it doesn't have to be the tutorial I linked to).
We have DynamoDB local working with gradle. Here's what you need to add to your gradle.build file:
For gradle 4.x and below versions
1) Add to the repositories section:
maven {
url 'http://dynamodb-local.s3-website-us-west-2.amazonaws.com/release'
}
2) Add to the dependencies section (assuming you're using this for your tests):
testCompile group: 'com.amazonaws', name: 'DynamoDBLocal', version: 1.11.0
3) These next two steps are the tricky part. First copy the native files to a directory:
task copyNativeDeps(type: Copy) {
from (configurations.testCompile) {
include "*.dylib"
include "*.so"
include "*.dll"
}
into 'build/libs'
}
4) Then make sure you include this directory (build/libs in our case) in the java library path like so:
test.dependsOn copyNativeDeps
test.doFirst {
systemProperty "java.library.path", 'build/libs'
}
Now you should be able to run ./gradlew test and have your tests hit your local DynamoDB.
这篇关于作为 Gradle Java 项目的一部分在本地运行 Dynamodb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!