【问题标题】:Execution failed for task ':run'. > Process 'command...finished with non-zero exit value 1任务 ':run' 执行失败。 > Process 'command...finished with non-zero exit value 1
【发布时间】:2018-11-27 02:34:15
【问题描述】:

不确定我的 build.gradle 文件有什么问题。我对 gradle 很陌生,所以我不理解这个错误。它允许我运行 gradle build、gradle init、gradle 任务等,但是当我运行“gradle run”时构建失败

screenshot of my command line

这是我的 build.gradle:

 plugins {
 id  'com.github.spotbugs' version '1.6.5'
 }

apply plugin: 'application'

///////////////////////////////////////////////////////////////////////////
// Definint Main class
///////////////////////////////////////////////////////////////////////////
mainClassName = 'main.java.main'


repositories {
  mavenCentral()
}
dependencies {
    compile "junit:junit:4.12"

}



///////////////////////////////////////////////////////////////////////////
// Configure Checkstyle
///////////////////////////////////////////////////////////////////////////
apply plugin: 'checkstyle'
checkstyle {
  // Keep checkstyle a little quieter
  ignoreFailures = true
  showViolations = false
}

tasks.withType(Checkstyle) {
  reports {
    html.enabled = true
    xml.enabled = false
  }
}
checkstyle {
    toolVersion = "8.8"
}


///////////////////////////////////////////////////////////////////////////
// Configure SpotBugs
///////////////////////////////////////////////////////////////////////////

// The part below needs to be included for Spotbugs
 spotbugs {
   toolVersion = '3.1.1'
 }

// // To generate an HTML report instead of XML
 tasks.withType(com.github.spotbugs.SpotBugsTask) {
   reports {
     xml.enabled = false
     html.enabled = true
   }
 }

【问题讨论】:

    标签: java eclipse gradle


    【解决方案1】:

    您已将主类设置为

    mainClassName = 'main.java.main'

    检查这是否正确。该值应该是主类的完全限定名称,即包含main() 方法的类。

    【讨论】:

      【解决方案2】:

      很可能在您的主要方法中使用 Scanner。使用

      在代码需要时传递参数
      gradle run --args='getItDone'
      

      2。选项 在您的 build.gradle 文件中包含此代码

      run{
          standardInput = System.in
      }
      

      并在终端中仅使用 gradle run 来运行它。

      我很自豪你参加了 SER 316。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-05
        • 1970-01-01
        • 1970-01-01
        • 2021-12-30
        • 2018-09-24
        • 1970-01-01
        相关资源
        最近更新 更多