作为Gradle Java项目的一部分运行Dynamodb local [英] Run Dynamodb local as part of a Gradle Java project

查看:66
本文介绍了作为Gradle Java项目的一部分运行Dynamodb local的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图出于测试目的在本地运行DynamoDB.我遵循了Amazon提供的步骤来设置和运行jar本身可以正常工作(链接到Amazon的教程

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.

这就是我的问题所在.作为测试的一部分,我很难在网上找到任何有关如何配置Gradle项目以运行DynamoDB本地服务器的示例.我发现以下maven示例

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.

我进入了他们项目的pom,并将以下内容放入我的 build.gradle 文件中进行仿真.

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

任何人都可以使DynamoDB本地JAR作为Gradle项目的一部分执行,或者有指向优秀教程的链接(不必是我链接的教程).

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).

推荐答案

我们在DynamoDB本地使用gradle.这是您需要添加到gradle.build文件中的内容:

We have DynamoDB local working with gradle. Here's what you need to add to your gradle.build file:

适用于gradle 4.x及以下版本

1)添加到存储库部分:

1) Add to the repositories section:

    maven {
        url 'http://dynamodb-local.s3-website-us-west-2.amazonaws.com/release'
    }

2)添加到依赖项"部分(假设您正在使用它进行测试):

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)接下来的两个步骤是棘手的部分.首先将本机文件复制到目录:

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)然后确保您将此目录(在本例中为build/libs)包含在java库路径中,如下所示:

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'
}

现在,您应该可以运行./gradlew测试,并使您的测试命中本地DynamoDB.

Now you should be able to run ./gradlew test and have your tests hit your local DynamoDB.

这篇关于作为Gradle Java项目的一部分运行Dynamodb local的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆