Java 我如何实施;“应用程序运行”;格拉德尔的任务?

Java 我如何实施;“应用程序运行”;格拉德尔的任务?,java,gradle,gradle-plugin,jmonkeyengine,gradle-task,Java,Gradle,Gradle Plugin,Jmonkeyengine,Gradle Task,我正在使用Gradle,我想知道如何实现run任务,以便可以从命令“/gradlew run”运行程序。我有一个名为“demo”的项目,它的任务是“应用程序运行”。然后我创建了项目“HouseObserver”,它没有任务“应用程序运行” 我的build.gradle文件如下所示 plugins { // Apply the java-library plugin to add support for Java Library id 'java-library' } repo

我正在使用Gradle,我想知道如何实现run任务,以便可以从命令“/gradlew run”运行程序。我有一个名为“demo”的项目,它的任务是“应用程序运行”。然后我创建了项目“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'

}

看看你是否能从bootmonkey的工作中找到一些灵感:看看gradle应用程序插件,这个插件将为运行任务添加广告automatically@RoiEX应用程序{}部分是,mainClassName=partno@RoiEX对它正在工作。我必须先关闭然后再打开项目,这样才能重新加载任务。看看你是否能从bootmonkey的工作中找到一些灵感:看看gradle应用程序插件,这个插件将为运行任务添加广告automatically@RoiEX应用程序{}部分是,mainClassName=partno@RoiEX对它正在工作。我必须先关闭项目,然后再打开项目,这样才能重新加载任务。