在Gradle任务中构建并运行一个jar [英] Build and run a jar inside of a Gradle task
问题描述
我正在使用Java,Spring和Gradle。我对gradle很陌生,我正在努力去理解一些东西。我目前已经成功地构建了一个jar文件。
我想添加一个任务,以便Gradle运行它构建的jar。
这样我就可以做
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $'
或者如果可能的话,我可以在一个命令中完成。它的伪代码将是
任务运行{
clean
build
java -jar myJar.jar
}
我该如何去做这件事?
--- INFO ----
我当前的build.gradle文件:
buildscript {
repositories {
maven {urlhttp://repo.spring.io/libs-snapshot}
mavenLocal ()
}
依赖关系{
classpath(org.springframework.boot:spring-boot-gradle-plugin:0.5.0.M6)
}
}
apply plugin:'java'
apply plugin:'eclipse'
apply plugin:'idea'
apply plugin:'spring-boot '
jar {
baseName ='gs-rest-service'
version ='0.1.0'
}
repositories {
mavenCentral()
maven {urlhttp://repo.spring.io/libs-snapshot}
}
依赖关系{
编译(org.springframework.boot :spring-boot-starter-web:0.5.0.M6)
compile(com.fasterxml.jackson.core:jackson-databind)
testCompile(junit:junit:4.11)
任务包装器(类型:包装器){
gradleVersion ='1.10'
}
在任务依赖关系中思考是非常重要的。 run
不会顺序执行一些其他任务(任务不能这样做);相反,它会在其前提条件上声明任务依赖关系,例如 jar
。无论如何,最简单的解决方案就是应用应用程序
插件,您可以在 Gradle用户指南。
I am using Java, Spring, and Gradle. I am new to gradle and am trying to understand some stuff. I currently have gradle successfully building a jar file. I would like to add a task so that gradle runs the jar that it builds. this way I could do
./gradlew clean build run
or I could just do it in one command if possible. The pseudocode of which would be
task run {
clean
build
java -jar myJar.jar
}
How would I go about doing this?
---INFO----
my current build.gradle file:
buildscript {
repositories {
maven { url "http://repo.spring.io/libs-snapshot" }
mavenLocal()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:0.5.0.M6")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'gs-rest-service'
version = '0.1.0'
}
repositories {
mavenCentral()
maven { url "http://repo.spring.io/libs-snapshot" }
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web:0.5.0.M6")
compile("com.fasterxml.jackson.core:jackson-databind")
testCompile("junit:junit:4.11")
}
task wrapper(type: Wrapper) {
gradleVersion = '1.10'
}
It's important to think in task dependencies. run
wouldn't execute some other tasks sequentially (tasks can't do that); rather, it would declare task dependencies on its prerequisites, such as perhaps jar
. Anyway, the easiest solution is to just apply the application
plugin, which you can learn more about in the Gradle User Guide.
这篇关于在Gradle任务中构建并运行一个jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!