java - 如何在 Gradle 中实现“应用程序运行”任务?
问题描述
我正在使用 Gradle,我想知道如何实现运行任务,以便可以从命令“./gradlew run”运行程序。我有一个名为“演示”的项目,它的任务是“应用程序运行”。然后我创建了项目“HouseObserver”,它没有任务“应用程序运行”。
我的 build.gradle 文件看起来像这样。
plugins {
// Apply the java-library plugin to add support for Java Library
id 'java-library'
}
repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
apply plugin: 'java'
task runApp(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'HouseObserver.Main'
}
// Using and creating an Executable Jar
jar {
manifest {
attributes('Main-Class': 'HouseObserver.Main')
}
}
task runExecutableJar(type: JavaExec) {
// Executable jars can have only _one_ jar on the classpath.
classpath = files(tasks.jar)
// 'main' does not need to be specified
}
dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:28.0-jre'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
// Need at least basic JME
compile "org.jmonkeyengine:jme3-core:3.3.0-beta1"
compile "org.jmonkeyengine:jme3-desktop:3.3.0-beta1"
compile "org.jmonkeyengine:jme3-lwjgl3:3.3.0-beta1"
compile group: 'com.simsilica', name: 'lemur', version: '1.13.0'
compile group: 'com.simsilica', name: 'lemur-proto', version: '1.11.0'
// needed for the style language
runtime "org.codehaus.groovy:groovy-all:2.4.5"
// Standard utility stuff
compile 'com.google.guava:guava:19.0'
compile 'org.slf4j:slf4j-api:1.7.13'
runtime 'org.apache.logging.log4j:log4j-slf4j-impl:2.5'
runtime 'org.apache.logging.log4j:log4j-core:2.5'
}
我也在尝试从插件中实现任务的方法。
plugins {
id 'application'
}
application {
mainClassName = 'my.packages.to.the.Main'
}
但什么也没有发生。为什么?
编辑:
这是我最新的 gradle 文件。
plugins {
// Apply the java-library plugin to add support for Java Library
id 'java-library'
id 'application'
}
application {
mainClassName = 'HouseObserver.Main'
}
repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:28.0-jre'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
// Need at least basic JME
compile "org.jmonkeyengine:jme3-core:3.3.0-beta1"
compile "org.jmonkeyengine:jme3-desktop:3.3.0-beta1"
compile "org.jmonkeyengine:jme3-lwjgl3:3.3.0-beta1"
compile group: 'com.simsilica', name: 'lemur', version: '1.13.0'
compile group: 'com.simsilica', name: 'lemur-proto', version: '1.11.0'
// needed for the style language
runtime "org.codehaus.groovy:groovy-all:2.4.5"
// Standard utility stuff
compile 'com.google.guava:guava:19.0'
compile 'org.slf4j:slf4j-api:1.7.13'
runtime 'org.apache.logging.log4j:log4j-slf4j-impl:2.5'
runtime 'org.apache.logging.log4j:log4j-core:2.5'
}
解决方案
推荐阅读
- python - AttributeError: _Connection__connection 使用 sqlalchemy 提交会话时
- bash - “期望”命令行脚本连接到 VPN 并输入密码
- node.js - api design - 如何设计公共 POST api 以防止垃圾邮件请求
- php - 如何在控制器 Laravel 7 中更改数据库中的日期格式
- matplotlib - 在 matplotlib 中绘制 2 个字典
- hash - 当 Sha256 和 md5 加在一起时
- c - '(struct student *)&st' 是一个指针;你的意思是使用'->'吗?|
- python - 在 3 个不同的集合中获得所有可能的组合
- c# - 如何知道一个 GameObject 在 Unity 中是否有网格?
- c++ - Toolbar / CreateToolbarEx 问题 C++ 不显示所有位图