如何使用gradle创建Dropwizard项目?

时间:2017-11-30 09:23:09

标签: java gradle junit dropwizard

我在使用Idea IntelliJ的Linux机器上,我想用gradle创建一个Dropwizard项目。使用maven原型,这项工作将非常容易。

mvn archetype:generate 
-DarchetypeGroupId=io.dropwizard.archetypes 
-DarchetypeArtifactId=java-simple 
-DarchetypeVersion=[REPLACE ME WITH A VALID DROPWIZARD VERSION]

对于gradle,我正在努力开始。当我查看其他帖子时,我想知道我所做的是否正确:

// Needed Instead of the Shade plug in 
plugins {
    id 'com.github.johnrengelman.shadow' version '2.0.1'
}

version '1.0-SNAPSHOT'
group 'org.example.sampleName'
description 'Sample Dropwizard REST '

apply plugin: 'java'
apply plugin: 'application'

repositories {
    mavenCentral()
}

dependencies {
    compile 'io.dropwizard:dropwizard-core:1.2.0'

    testCompile 'junit:junit:4.12'
}

mainClassName = 'org.example.sampleName.SampleApplication'

run {
    args = ['server', 'config.yml']
}

shadowJar {
    mergeServiceFiles()
    exclude 'META-INF/*.DSA', 'META-INF/*.RSA', 'META-INF/*.SF'

}

jar {
    manifest {
        attributes 'Main-Class': mainClassName
    }
}

然后我只需运行gradle shadowJar,然后运行java -jar build/SampleApplication.jar server config.yml。它是否正确?第testCompile 'junit:junit:4.12'行是否足以进行单元测试?

1 个答案:

答案 0 :(得分:1)

你可以使用这个Yeoman发电机:

https://www.npmjs.com/package/generator-dropwizard-gradle

如果你安装了npm。

testCompile 'junit:junit:4.12'就足够了,是的。

您还可以在github上搜索示例,例如: https://github.com/kishaningithub/dropwizard-gradle